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

cancelling and/or pausing job when running #2473

Open
harmen46 opened this issue Nov 26, 2024 · 2 comments
Open

cancelling and/or pausing job when running #2473

harmen46 opened this issue Nov 26, 2024 · 2 comments

Comments

@harmen46
Copy link

it would be nice if you could cancel or pause a job

@DMiradakis
Copy link

You can cancel a specific job using cooperative cancellation and a CancellationToken, see this link from the Hangfire docs.

However, pausing the entire execution engine is something that does not(?) seem possible at the moment. See #225 .

@andre-ss6
Copy link

andre-ss6 commented Jan 16, 2025

The docs say that Hangfire will provide its own CancellationToken as argument. How do I get the CancellationTokenSource for that in order to call Cancel on it?

... Though I'm not sure if that would even be necessary? I'm seeing conflicting information on SO, docs and elsewhere regarding job deletion and cancellation. This SO answer and others I've seen say that deleting a job would trigger its CancellationToken.

However, the documentation for Hangfire.BackgroundJobClientExtensions.Delete say, on its remarks (emphasis mine):

// The job is not actually being deleted, this method changes only its state. This
// operation does not provide guarantee that the job will not be performed. If you
// are deleting a job that is performing right now, it will be performed anyway,
// despite of this call.
The method returns result of a state transition. It can
// be false if a job was expired, its method does not exist or there was an exception
// during the state change process.

So I'm confused. Does Hangfire trigger the CancellationToken when requesting a change to the Deleted state or do I need to provide Hangfire with a way to resolve a CancellationTokenSource so that it uses that instead so that I can call Cancel on it myself (some answers on SO say that is the right implementation), or something else...?

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

No branches or pull requests

3 participants