Issues with one time quartz .net job

I’m using .NET 8 and I’m trying to setup a Quartz Job.
What I want to achieve is that in production, this job must be scheduled (with a cron schedule), but in dev and in local I don’t need it scheduled, but I still need it to be registered because I want to be able to run a OneTimeJob from a Controller endpoint.
This is my setup:
Inside the Startup.cs

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code> var environmentType = Environment.Type;
services.AddQuartz();
services.AddQuartzHostedService(opt =>
{
opt.WaitForJobsToComplete = true;
});
if (Environment.Type == EnvironmentType.Production)
{
services.ConfigureOptions<ProcessIssuersJobSetupWithCron>();
}
else if (environmentType is EnvironmentType.TestingRc or EnvironmentType.TestingMaster or EnvironmentType.Staging or EnvironmentType.Local)
{
services.ConfigureOptions<ProcessIssuersJobSetupWithoutCron>();
}
</code>
<code> var environmentType = Environment.Type; services.AddQuartz(); services.AddQuartzHostedService(opt => { opt.WaitForJobsToComplete = true; }); if (Environment.Type == EnvironmentType.Production) { services.ConfigureOptions<ProcessIssuersJobSetupWithCron>(); } else if (environmentType is EnvironmentType.TestingRc or EnvironmentType.TestingMaster or EnvironmentType.Staging or EnvironmentType.Local) { services.ConfigureOptions<ProcessIssuersJobSetupWithoutCron>(); } </code>
        var environmentType = Environment.Type;
        services.AddQuartz();
        services.AddQuartzHostedService(opt =>
        {
            opt.WaitForJobsToComplete = true;
        });

        if (Environment.Type == EnvironmentType.Production)
        {
            services.ConfigureOptions<ProcessIssuersJobSetupWithCron>();
        }
        else if (environmentType is EnvironmentType.TestingRc or EnvironmentType.TestingMaster or EnvironmentType.Staging or EnvironmentType.Local)
        {
            services.ConfigureOptions<ProcessIssuersJobSetupWithoutCron>();
        }

Let’s focus on the WithoutCron job:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>public class ProcessIssuersJobSetupWithoutCron : IConfigureOptions<QuartzOptions>
{
public void Configure(QuartzOptions options)
{
var processIssuersJobKey = JobKey.Create("ProcessIssuersJob");
options
.AddJob<ProcessIssuersJob>(jobBuilder => jobBuilder.WithIdentity(processIssuersJobKey))
.AddTrigger(trigger =>
trigger
.ForJob(jobKey: processIssuersJobKey));
}
}
</code>
<code>public class ProcessIssuersJobSetupWithoutCron : IConfigureOptions<QuartzOptions> { public void Configure(QuartzOptions options) { var processIssuersJobKey = JobKey.Create("ProcessIssuersJob"); options .AddJob<ProcessIssuersJob>(jobBuilder => jobBuilder.WithIdentity(processIssuersJobKey)) .AddTrigger(trigger => trigger .ForJob(jobKey: processIssuersJobKey)); } } </code>
public class ProcessIssuersJobSetupWithoutCron : IConfigureOptions<QuartzOptions>
{
    public void Configure(QuartzOptions options)
    {
        var processIssuersJobKey = JobKey.Create("ProcessIssuersJob");

        options
            .AddJob<ProcessIssuersJob>(jobBuilder => jobBuilder.WithIdentity(processIssuersJobKey))
            .AddTrigger(trigger =>
                trigger
                    .ForJob(jobKey: processIssuersJobKey));
    }
}

And from my Controller I try to trigger that in this way:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>public class QuartzController(ISchedulerFactory scheduleFactory) : Controller
{
private readonly ISchedulerFactory _scheduleFactory = scheduleFactory;
[HttpPost("ProcessIssuers")]
public async Task<IActionResult> ExecuteDataStoredProcedures([FromQuery] DateTime runDate)
{
var scheduler = await this._scheduleFactory.GetScheduler();
var jobKey = JobKey.Create("ProcessIssuersJob");
var jobDataMap = new JobDataMap();
jobDataMap.Put("runDate", runDate);
await scheduler.TriggerJob(jobKey, jobDataMap);
return this.Ok();
}
}
</code>
<code>public class QuartzController(ISchedulerFactory scheduleFactory) : Controller { private readonly ISchedulerFactory _scheduleFactory = scheduleFactory; [HttpPost("ProcessIssuers")] public async Task<IActionResult> ExecuteDataStoredProcedures([FromQuery] DateTime runDate) { var scheduler = await this._scheduleFactory.GetScheduler(); var jobKey = JobKey.Create("ProcessIssuersJob"); var jobDataMap = new JobDataMap(); jobDataMap.Put("runDate", runDate); await scheduler.TriggerJob(jobKey, jobDataMap); return this.Ok(); } } </code>
public class QuartzController(ISchedulerFactory scheduleFactory) : Controller
{
    private readonly ISchedulerFactory _scheduleFactory = scheduleFactory;

    [HttpPost("ProcessIssuers")]
    public async Task<IActionResult> ExecuteDataStoredProcedures([FromQuery] DateTime runDate)
    {
        var scheduler = await this._scheduleFactory.GetScheduler();
        var jobKey = JobKey.Create("ProcessIssuersJob");

        var jobDataMap = new JobDataMap();
        jobDataMap.Put("runDate", runDate);

        await scheduler.TriggerJob(jobKey, jobDataMap);

        return this.Ok();
    }
}

but when it comes to the await.scheduler.TriggerJob(jobKey, jobDataMap); I’m getting this error:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>Exception Type: Quartz.JobPersistenceException
Error message: The job (DEFAULT.ProcessIssuersJob) referenced by the trigger does not exist.
</code>
<code>Exception Type: Quartz.JobPersistenceException Error message: The job (DEFAULT.ProcessIssuersJob) referenced by the trigger does not exist. </code>
Exception Type: Quartz.JobPersistenceException
Error message: The job (DEFAULT.ProcessIssuersJob) referenced by the trigger does not exist.

I tried to debug and it actually arrives inside the ProcessIssuersJobSetupWithoutCron Configure method, and the key is the same: DEFAULT.ProcessIssuersJob .
What am I doing wrong? I’m not 100% but I think when I was using the ProcessIssuersWithCron it was working the one time job.. here’s the setup with cron::

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>public class ProcessIssuersJobSetupWithCron : IConfigureOptions<QuartzOptions>
{
private static readonly string MonthlyJobCronExpression;
static ProcessIssuersJobSetupWithCron()
{
MonthlyJobCronExpression = AppSettingBuilder<string>
.Create("MonthlyJobCronExpression", System.Configuration.ConfigurationManager.AppSettings)
.ToSetting()
.Value;
}
public void Configure(QuartzOptions options)
{
var processIssuersJobKey = JobKey.Create("ProcessIssuersJob");
if (MonthlyJobCronExpression.IsNullOrEmpty())
{
return;
}
options
.AddJob<ProcessIssuersJob>(jobBuilder => jobBuilder.WithIdentity(processIssuersJobKey))
.AddTrigger(trigger =>
trigger
.ForJob(jobKey: processIssuersJobKey)
.WithCronSchedule(MonthlyJobCronExpression, cron => cron.InTimeZone(TimeZoneInfo.Utc)));
}
}
</code>
<code>public class ProcessIssuersJobSetupWithCron : IConfigureOptions<QuartzOptions> { private static readonly string MonthlyJobCronExpression; static ProcessIssuersJobSetupWithCron() { MonthlyJobCronExpression = AppSettingBuilder<string> .Create("MonthlyJobCronExpression", System.Configuration.ConfigurationManager.AppSettings) .ToSetting() .Value; } public void Configure(QuartzOptions options) { var processIssuersJobKey = JobKey.Create("ProcessIssuersJob"); if (MonthlyJobCronExpression.IsNullOrEmpty()) { return; } options .AddJob<ProcessIssuersJob>(jobBuilder => jobBuilder.WithIdentity(processIssuersJobKey)) .AddTrigger(trigger => trigger .ForJob(jobKey: processIssuersJobKey) .WithCronSchedule(MonthlyJobCronExpression, cron => cron.InTimeZone(TimeZoneInfo.Utc))); } } </code>
public class ProcessIssuersJobSetupWithCron : IConfigureOptions<QuartzOptions>
{
    private static readonly string MonthlyJobCronExpression;

    static ProcessIssuersJobSetupWithCron()
    {
        MonthlyJobCronExpression = AppSettingBuilder<string>
            .Create("MonthlyJobCronExpression", System.Configuration.ConfigurationManager.AppSettings)
            .ToSetting()
            .Value;
    }

    public void Configure(QuartzOptions options)
    {
        var processIssuersJobKey = JobKey.Create("ProcessIssuersJob");

        if (MonthlyJobCronExpression.IsNullOrEmpty())
        {
            return;
        }

        options
            .AddJob<ProcessIssuersJob>(jobBuilder => jobBuilder.WithIdentity(processIssuersJobKey))
            .AddTrigger(trigger =>
                trigger
                    .ForJob(jobKey: processIssuersJobKey)
                    .WithCronSchedule(MonthlyJobCronExpression, cron => cron.InTimeZone(TimeZoneInfo.Utc)));
    }
}

2

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật