HangfireIO / HangfireIO/Hangfire
delayed jobs not deleted from queue
- Dominant language
- C#
- Stars
- 10.1k
- Forks
- 1.8k
- Avg merge
- 1h 19m
- Merged PRs (30d)
- 1
Description
Is it possible that a delayed job once fired is not deleted from the job queue ?
Or alternately that for some reason Hangfire itself clones the job and places it on the queue ?
Here's my scenario : My application must process many tasks in parallel each of which must wait for a task-specific row to be written to an external database by an external application.
So for each task I schedule a delayed job passing in a single parameter unique id to the invoked method. If the method doesn't find an external database row related to the unique id then its final action is to create another identical delayed job with the same unique id parameter.
NOTE : The unique id is a tracking id for the set of task-specific data stored in my database and is auto-generated by an identity column.
I would expect that a running job once complete would delete itself - so that at any given time the job queue would contain at most one instance of a job with a specific unique id parameter.
But my application logs indicate multiple jobs ( 4-12x ) with the same unique id parameter firing in very close proximity ( a few ms apart ).
I can't find any explanation other than Hangfire is not deleting these supposedly one-time delayed jobs once completed.
```
BackgroundJob.Schedule( () => MyMethod(uniqueInteger, CancellationToken.None), TimeSpan.FromSeconds(30));
[AutomaticRetry(Attempts = 0)]
[Queue("myqueue")]
public static void MyMethod(int id, CancellationToken token )
{
// log MyMethod triggered with id
// do processing - check if expected row written to external database
// if row not found then schedule another job to continue processing later
BackgroundJob.Schedule( () => MyMethod(id, CancellationToken.None), TimeSpan.FromSeconds(30));
}
```
Contributor guide
Research direction
Start with the BackgroundJob.Schedule calls and the MyMethod flow shown in the report, then compare scheduled jobs with the application logs for the repeated unique id. Done means determining whether repeated scheduling or queue behavior accounts for the near-simultaneous executions and documenting the observed behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100