Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handling job class removals/changes #49

Closed
leonluc-dev opened this issue Jul 5, 2024 · 1 comment
Closed

Handling job class removals/changes #49

leonluc-dev opened this issue Jul 5, 2024 · 1 comment

Comments

@leonluc-dev
Copy link

leonluc-dev commented Jul 5, 2024

I currently have a job added like this:

JobKey jobKey = new JobKey("MyTestJobKey", "TestGroup");
services.AddJob<MyTestJob>(jobKey, j => j
    .WithDescription("A test job")
);

This job is properly persisted in the MongoDB database. However, an issue arises when I need to change the class name of MyTestJob.
Once I change the class name (for example from MyTestJob to MyTestJob2) or remove the class altogether and re-run the scheduler, the scheduler factory fails with the following error:

Quartz.JobPersistenceException: Job class cannot be null.
 ---> System.ArgumentException: Job class cannot be null.
   at Quartz.Impl.JobDetailImpl.set_JobType(Type value)
   at Quartz.Impl.JobDetailImpl..ctor(JobKey key, Type jobType, String description, Boolean isDurable, Boolean requestsRecovery, JobDataMap jobDataMap, Nullable`1 disallowConcurrentExecution, Nullable`1 persistJobDataAfterExecution)
   at Quartz.JobBuilder.Build()
   at Quartz.Spi.MongoDbJobStore.Models.JobDetail.GetJobDetail()
   at Quartz.Spi.MongoDbJobStore.MongoDbJobStore.ReplaceTriggerInternal(TriggerKey triggerKey, IOperableTrigger newTrigger)
   at Quartz.Spi.MongoDbJobStore.MongoDbJobStore.ReplaceTrigger(TriggerKey triggerKey, IOperableTrigger newTrigger, CancellationToken token)
   --- End of inner exception stack trace ---
   at Quartz.Spi.MongoDbJobStore.MongoDbJobStore.ReplaceTrigger(TriggerKey triggerKey, IOperableTrigger newTrigger, CancellationToken token)
   at Quartz.Core.QuartzScheduler.RescheduleJob(TriggerKey triggerKey, ITrigger newTrigger, CancellationToken cancellationToken)
   at Quartz.Xml.XMLSchedulingDataProcessor.ScheduleJobs(IScheduler sched, CancellationToken cancellationToken)
   at Quartz.ServiceCollectionSchedulerFactory.InitializeScheduler(IScheduler scheduler, CancellationToken cancellationToken)
   at Quartz.ServiceCollectionSchedulerFactory.GetScheduler(CancellationToken cancellationToken)

This is expected, as the class name it's trying to restore no longer exists. But is there a way to gracefully handle this and remove or ignore any jobs that no longer have a valid class associated with them from the MongoDB store?

@leonluc-dev
Copy link
Author

The above error relates to #48 , so I've merged the two issues and closed this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant