HangfireIO / HangfireIO/Hangfire
Monitoring API ScheduledJobs returns ScheduledJobDtos with null jobs
- Dominant language
- C#
- Stars
- 10.1k
- Forks
- 1.8k
- Avg merge
- 1h 19m
- Merged PRs (30d)
- 1
Description
I ran into an issue while executing a linq query against scheduled jobs. While this is very recoverable, I am interested to know about how this works and if I should be concerned with anything.
Here’s where I got in trouble:
`if (!monitor.ScheduledJobs(startAt,takeSoMuch).Any(j => j.Value.Job.Method.Name == "foobar" && x.Value.Job.Args[index].ToString == configurationStuff) {dowork()};`
This morning (after months working okay), I started getting a null reference exception, which I narrowed down to j.Value.Job.
Then I made the following code to test this:
```
Hangfire.Storage.IMonitoringApi monitor = JobStorage.Current.GetMonitoringApi();
var schedules = monitor.ScheduledJobs(startAt,takeSoMuch);
var jobs = schedules.Where(x => x.Value.Job == null);
```
I got three job IDs, which I then cross-referenced in the database:
```
DECLARE @IDs table (val int);
INSERT INTO @IDs VALUES (26511), (26510), (26503);
SELECT * FROM [Hangfire].[Set]
WHERE Value IN (SELECT val FROM @IDs);
SELECT * FROM [Hangfire].[Job]
WHERE Id IN (SELECT val FROM @IDs);
SELECT * FROM [Hangfire].[JobParameter]
WHERE JobId IN (SELECT val FROM @IDs);
```
I got three sets of results, the most interesting being that all columns (except ExpireAt) in the Job table were filled out for each of the IDs. I cross-referenced with code again, thinking that maybe the table was lagging behind, but that was not the case, the records existed in the table, but the code didn’t show matching objects.
So I went deeper and figured out that this error only existed in those versions of the application which did not have the invoked methods.
So… Is Hangfire supposed to interface with incompatible schedules as jobless schedules, or is this some bug?
If it is supposed to behave like that, can we schedule jobs to specific queues, so that we could narrow down in the same way as with `monitor.EnqueuedJobs(queuename, from, perPage)` so that different codebases using the same database do not interfere with each other?
Contributor guide
Research direction
Start at the IMonitoringApi ScheduledJobs call and compare its results with the Job, Set, and JobParameter records shown in the SQL queries. Reproduce the case using an application version without the invoked method, then determine whether null Job values are intended; done means the behavior is clarified or corrected and the queue-filtering request is explicitly addressed.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100