HangfireIO / HangfireIO/Hangfire
How to cancel running hangfire job?
- Dominant language
- C#
- Stars
- 10.1k
- Forks
- 1.8k
- Avg merge
- 1h 19m
- Merged PRs (30d)
- 1
Description
public class JobController : Controller {
public void InternalLogic(int id, CancellationToken cancellationToken)
{
foreach (var item in collection)
{
if (someCondition)
{
if (cancellationToken.IsCancellationRequested)
{
//some logic
break;
}
//continue working
}
}
}
public void RunLogic(int id, CancellationToken cancellationToken)
{
//some logic
InternalLogic(id,cancellationToken);
}
public void Run(int id, CancellationToken cancellationToken)
{
var jobId = BackgroundJob.Enqueue(() => this.RunLogic(id, cancellationToken));
}
}
This is my codebase. I need to stop running job. I've tried `BackgroundJob.Delete` method and send current jobId but it didn't help.I can't cancel running job neither using `CancellationToken` nor `BackgroundJob.Delete` Any suggestions?
Contributor guide
Research direction
Start by reviewing the issue's BackgroundJob.Enqueue and BackgroundJob.Delete calls alongside the CancellationToken usage shown in the example. Determine and document the supported behavior for stopping an already-running job, including what completion criteria should be demonstrated for the example.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- backend
- Issue type
- Documentation
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100