SilkierQuartz Documentation

repository·master·Indexed 19 days ago

https://github.com/iotsharp/silkierquartz

A web management tool for Quartz.NET that combines the capabilities of Quartzmin and QuartzHostedService. It provides a dashboard for managing jobs, triggers, and calendars, and includes a system for persisting and viewing job execution history via EF Core providers (SQL Server, PostgreSQL, SQLite, MySQL) or ADO.NET.

Tokens
2.2K
Snippets
7
Records
9
Agent score
14%

What's inside SilkierQuartz

  1. SilkierQuartz Package Overview

    master

    SilkierQuartz is composed of several packages depending on your needs:

    • SilkierQuartz: The main web UI package containing the dashboard, job editing, and monitoring.
    • SilkierQuartz.Plugins.RecentHistory: The core plugin for recording execution history.
    • SilkierQuartz.Plugins.RecentHistory.EFCore.[Provider]: Specific packages for persisting history to SQL Server, PostgreSQL, SQLite, or MySQL using EF Core.
  2. Install SilkierQuartz via NuGet

    master

    SilkierQuartz and its history plugins are available on NuGet. Use the Package Manager Console to install the main package and any specific EF Core provider packages for persisting execution history.

    # Install the main web UI package
    PM> Install-Package SilkierQuartz
    
    # Install a provider package for persistent execution history
    PM> Install-Package SilkierQuartz.Plugins.RecentHistory.EFCoreSqlServer
    PM> Install-Package SilkierQuartz.Plugins.RecentHistory.EFCoreNpgsql
    PM> Install-Package SilkierQuartz.Plugins.RecentHistory.EFCoreSqlite
    PM> Install-Package SilkierQuartz.Plugins.RecentHistory.EFCoreMySql
  3. Configure SilkierQuartz in ASP.NET Core

    master

    To integrate SilkierQuartz into an ASP.NET Core application, you need to configure the host, register services, and add the middleware.

    1. Host Configuration: Use .ConfigureSilkierQuartzHost() in your Program.cs (or equivalent host builder).
    2. Service Registration: Call services.AddSilkierQuartz() in ConfigureServices. You can also register an execution history store using services.AddExecutionHistoryStore(...).
    3. Middleware: Add app.UseSilkierQuartz(options) in Configure to enable the dashboard at a specific VirtualPathRoot.
    // 1. Program.cs configuration
    public static IHostBuilder CreateHostBuilder(string[] args) =>
        Host.CreateDefaultBuilder(args)
            .ConfigureWebHostDefaults(webBuilder =>
            {
                webBuilder.UseStartup<Startup>();
            })
         .ConfigureSilkierQuartzHost();
    
    // 2. Startup.cs - ConfigureServices
    public void ConfigureServices(IServiceCollection services)
    {
        services.AddSilkierQuartz();
        services.AddExecutionHistoryStore(setting =>
            setting.UseSqlite("Data Source=silkierquartz-history.db"));
    }
    
    // 3. Startup.cs - Configure
    public void Configure(IApplicationBuilder app)
    {
        app.UseSilkierQuartz(new SilkierQuartzOptions()
                    {
                        Scheduler = scheduler,
                        VirtualPathRoot = "/SilkierQuartz",
                        UseLocalTime = true,
                        DefaultDateFormat = "yyyy-MM-dd",
                        DefaultTimeFormat = "HH:mm:ss"
                    });
    }
  4. Configure the Execution History Store

    master

    SilkierQuartz allows you to persist job execution history using EF Core providers or a generic ADO.NET provider.

    If using EF Core, use the specific provider methods like UseSqlite, UseSqlServer, etc. For applications managing their own ADO.NET provider factory, use UseAdoProvider to specify the invariant name, connection string, and factory instance.

    // Using EF Core (example with SQLite)
    services.AddExecutionHistoryStore(setting =>
        setting.UseSqlite("Data Source=silkierquartz-history.db"));
    
    // Using a generic ADO.NET provider
    services.AddExecutionHistoryStore(setting =>
        setting.UseAdoProvider(
            providerInvariantName: "Microsoft.Data.SqlClient",
            connectionString: configuration.GetConnectionString("QuartzHistory"),
            providerFactory: SqlClientFactory.Instance));
  5. SilkierQuartzOptions Reference

    master

    The SilkierQuartzOptions object is used when calling app.UseSilkierQuartz() to customize the dashboard behavior.

    Key properties include:

    • Scheduler: The Quartz scheduler instance.
    • VirtualPathRoot: The URL path where the dashboard is hosted (e.g., /SilkierQuartz).
    • UseLocalTime: Boolean to determine if local time should be used.
    • DefaultDateFormat: String format for dates (e.g., yyyy-MM-dd).
    • DefaultTimeFormat: String format for times (e.g., HH:mm:ss).
    • AccountName / AccountPassword: Credentials for the optional authentication feature.
    • IsAuthenticationPersist: Boolean for authentication persistence.
  6. Retrieve registered type handler scripts

    master

    Call TypeHandlerService.GetScripts() to retrieve a dictionary of all registered type handlers that have associated scripts.

    The returned Dictionary<string, string> uses the handler's TypeId as the key and the raw script content as the value. This is useful for exposing client-side logic or scripts associated with specific job types.

    Dictionary<string, string> scripts = typeHandlerService.GetScripts();
    // Example access:
    // string myScript = scripts["my_type_id"];
  7. Render type handler templates

    master

    Use TypeHandlerService.Render(TypeHandlerBase typeHandler, object model) to generate a string representation of a type handler using its associated Handlebars template and a provided data model.

    If the type handler has not been registered via Register(), this method will throw an InvalidOperationException.

    // Renders the handler's template using the provided model
    string output = typeHandlerService.Render(myHandler, myDataModel);
  8. Register custom job data type handlers

    master

    Use TypeHandlerService.Register(Type type) to register a custom type handler. The type must inherit from TypeHandlerBase.

    When a type is registered, the service:

    1. Extracts its TypeId.
    2. Resolves its resources (templates and scripts) via the TypeHandlerResourcesAttribute.
    3. Compiles a Handlebars template for rendering.
    4. Configures JSON subtype converters to ensure correct polymorphic serialization/deserialization.

    Note: Registering a new type resets the internal JSON serializer settings cache.

    // Assuming typeHandlerClass inherits from TypeHandlerBase
    typeHandlerService.Register(typeof(MyCustomTypeHandler));
  9. Serialize and deserialize type handlers

    master

    The TypeHandlerService provides methods to convert TypeHandlerBase instances to and from Base64-encoded JSON strings, which is useful for storing job data in databases or message queues.

    • Serialize(TypeHandlerBase typeHandler): Converts the handler to a Base64-encoded JSON string using polymorphic subtype handling.
    • Deserialize(string str): Decodes a Base64 string and deserializes it back into the appropriate TypeHandlerBase implementation based on its TypeId.
    // Serialization
    string encodedData = typeHandlerService.Serialize(myHandler);
    
    // Deserialization
    TypeHandlerBase restoredHandler = typeHandlerService.Deserialize(encodedData);