Foundatio icon indicating copy to clipboard operation
Foundatio copied to clipboard

Cancel queue job and clear the queue. Also disable job

Open paulreicherdt opened this issue 3 years ago • 6 comments

Hi,

thanks for this great set of libraries. Really helpful.

Is there a way to cancel all queue jobs and clear the queue? We have some long running jobs that need to be cancelled on event. And afterwards, the user can enqueue the job again.

And is there a way to disable/deactivate a job via settings? E.g. if we want to disable some job on specific environments.

Kind regards Paul

paulreicherdt avatar Oct 26 '21 13:10 paulreicherdt

If you want to clear the queue you could call DeleteQueueAsync() but make sure you check the underlying implementation as it may completely delete the queue + configuration. We do this for our unit tests. Also you could always add a setting to your queue job and then look at that setting in dequeue to auto complete a queue entry.

niemyjski avatar Oct 26 '21 14:10 niemyjski

The question was - how to cancel an already running job (queue entry). So, usually, I would use CancellationTokenSource, create a CancellationToken, link it with others if necessary and then, I'm able to monitor this token and stop the job if cancellation were requested.

paulreicherdt avatar Oct 26 '21 15:10 paulreicherdt

I think what you are doing is the recommended way. @ejsmith, it might be nice to trigger the cancellation token we pass through to get cancelled from the passed in context?

niemyjski avatar Oct 26 '21 15:10 niemyjski

Yeah, not sure exactly. When you call dequeue it takes a cancellationtoken that can be cancelled to stop the processing as long as you are checking in your long running code for it to be cancelled periodically.

ejsmith avatar Oct 26 '21 16:10 ejsmith

Yes, sure, I need to check the cancellation token periodically. I do it. And using cancellation token I'm able to cancel my job on any place. Or even within .net library code. I have seen, that there is a cancellation token within job context. So, it may be a nice solution - to cancel all queued jobs by cancelling from the queue.

paulreicherdt avatar Oct 27 '21 07:10 paulreicherdt

Also, the possibility to disable a job would be nice. By e.g. instance count set to 0.

paulreicherdt avatar Oct 27 '21 07:10 paulreicherdt