0

Currently, we have a Quartz.NET application that is configured from the quartz_jobs.xml file. We want to move the configuration and execution responsibilities to SQL Server. I'm not quite sure how to store the job-data-map parameter entries in the database so they can be loaded from Quartz.NET and passed to the jobs.

If my research is correct, these parameters can be stored in the JOB_DATA column of the QRTZ_JOB_DETAILS table. However, I'm not sure how to store the data in this column. Our plan is to create a UI for the users to schedule their own jobs. They will need to be able to pass certain parameters into it.

Here is a snippet from our current quartz_jobs.xml file:

<schedule>
    <job>
        <name>AutoDistributionJob</name>
        <group>AutoDistributionJobGroup</group>
        <description>Executes the Auto Distribution job.</description>
        <job-type>Library.AutoWorkflowJob, Library</job-type>
        <durable>true</durable>
        <recover>false</recover>
        <job-data-map>
            <entry>
                <key>customerCode</key>
                <value>1234</value>
            </entry>
            <entry>
                <key>environmentType</key>
                <value>Test</value>
            </entry>
        </job-data-map>
    </job>
    <trigger>
        <cron>
            <name>AutoDistributionTrigger</name>
            <group>AutoDistributionTriggerGroup</group>
            <description>Trigger to start the Auto Distribution Job</description>
            <job-name>AutoDistributionJob</job-name>
            <job-group>AutoDistributionJobGroup</job-group>
            <cron-expression>0 0/1 * * * ?</cron-expression>
        </cron>
    </trigger>
</schedule>

The job-data-map section holds the parameters that are passed to the C# method.

public async Task Execute(IJobExecutionContext context)
{
    _logger.LogDebug("Entering AutoDistributionJob:Execute()");
    ArgumentNullException.ThrowIfNull(context, nameof(context));
    await Task.Run(() =>
    {
        try
        {
            var customerCode = context.JobDetail.JobDataMap.GetString("customerCode");
            var environmentType = context.JobDetail.JobDataMap.GetString("environmentType");
            ArgumentNullException.ThrowIfNullOrWhiteSpace(customerCode, nameof(customerCode));
            ArgumentNullException.ThrowIfNullOrWhiteSpace(environmentType, nameof(environmentType));

            _autoDistributionService.RunAutoDistribution(customerCode, environmentType, null, false);
        }
        catch (Exception ex)
        {
            _logger.LogError($"Error in AutoDistributionJob Execution: {ex.GetBaseException().Message}", ex);
        }
    });

    _logger.LogDebug("Leaving AutoDistributionJob:Execute()");
}

All of that works fine. I just can't seem to find a clear answer on how to store those parameters in the predefined Quartz.NET tables so they can be used. Any help would be greatly appreciated.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.