Cancel a running job

the use case is this : I have a long running job recurring job. At some point while it is processing I want to be able to cancel this job. I implemented JobCancellationToken per the docs. I register the job with :

var token = new JobCancellationToken(true);
RecurringJob.AddOrUpdate(“MyJobId”, o => o.Run(token), Cron.Minutely,null, myQueName");

The docs state that BackgroundJob.Delete(id) will fire the token. The problem is that you cannot pass “MyJobId” into the Delete method. You instead need to pass the integer which is the Id of the actual Job table in the database. HOW do I know which job instance to delete. I do not see any tie between the registered jobid of “MyJobId” and the processing jobId of say 3?

Thanks in advance!

2 Likes