Skip to content

Commit

Permalink
Make job querying more defensive
Browse files Browse the repository at this point in the history
  • Loading branch information
sfmskywalker committed Aug 11, 2023
1 parent 13aa380 commit 21914db
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,19 @@ public static IEnumerable<KeyValuePair<string, ScheduledJobDto>> EnumerateSchedu
jobList = api.ScheduledJobs(skip, take);

var jobs = jobList.FindAll(x => x.Value?.Job?.Type == typeof(TJob));
foreach (var job in jobs.Where(x => predicate((TJobModel)x.Value.Job.Args[0])))
yield return job;
foreach (var job in jobs)
{
var args = job.Value?.Job?.Args;

if (args is not { Count: 1 })
continue;

if(args[0] is not TJobModel jobModel)
continue;

if (predicate(jobModel))
yield return job;
}

skip += take;
} while (jobList.Count == take);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ private void DeleteAllRecurringJobs()
private IEnumerable<RecurringJobDto> QueryRecurringJobs()
{
using var connection = _jobStorage.GetConnection();
return connection.GetRecurringJobs().Where(x => x.Job.Type == typeof(RunHangfireWorkflowDefinitionJob));
return connection.GetRecurringJobs().Where(x => x?.Job?.Type == typeof(RunHangfireWorkflowDefinitionJob));
}

private void DeleteScheduledJob(RunHangfireWorkflowDefinitionJobModel data)
Expand Down

0 comments on commit 21914db

Please sign in to comment.