Hangfire.DynamicJobs icon indicating copy to clipboard operation
Hangfire.DynamicJobs copied to clipboard

Ensure queue name is added into dynamic job when adding recurring job using AddOrUpdateDynamic and using queue parameter

Open timpikelmg opened this issue 1 year ago • 0 comments

As noted in this issue 2259 when using AddOrUpdateDynamic to add a recurring job using DynamicJobs and setting the queue name via the parameter as recommended, the job does not run on the queue unless the Queue attribute is included in the job class/method or the Queue is set in the DynamicRecurringJobOptions.

manager.AddOrUpdateDynamic<INewsletterService>(
    "monthly-newsletter",
    x => x.SendMonthly(),
    Cron.Monthly(),
    new DynamicRecurringJobOptions()
    {
        Filters = new [] { new MyFilterAttribute("newsletter") },
        TimeZone = TimeZoneInfo.Local
    });

The above will run on the default queue.

This appears to be caused by when the DynamicJob is created it is not indicating which job to run on in the FromExpression, ie. return Job.FromExpression(() => DynamicJob.Execute(dynamicJob, default)); so it runs on the default queue unless one of the other ways to set the queue is used.

This changes the ToDynamicJob method so it will create the job to run and include the queue name so the dynamic job will run on the desired queue if it is set in the job.

timpikelmg avatar Mar 27 '24 04:03 timpikelmg