We use an IElectStateFilter to remove expired jobs.
public void OnStateElection(ElectStateContext context)
{
if (context.CurrentState == "Enqueued"
&& context.CandidateState is ProcessingState
&& context.BackgroundJob.CreatedAt < DateTime.UtcNow - _deleteJobAfter
&& (_queues is null ||
_queues.Any(q => context.BackgroundJob.Job.Queue.Equals(q, StringComparison.Ordinal))))
{
context.CandidateState = new DeletedState();
Logger.Warn($"Job {context.BackgroundJob.Job.Type.Name}.{context.BackgroundJob.Job.Method.Name} execution skipped because it was scheduled at {context.BackgroundJob.CreatedAt.ToLocalTime()}, which is more than {_deleteJobAfter.Minutes} minutes ago.");
}
}
However, the filter is configured to do this only for jobs being processed in a specific queue.
It worked perfectly with the SqlServer storage, but Hangfire.Redis.StackExchange does not seem to expose the queue name when it's queuing jobs.
context.BackgroundJob.Job.Queue is always null.
Hi there!
Thank you for the port.
We use an
IElectStateFilter
to remove expired jobs.However, the filter is configured to do this only for jobs being processed in a specific queue.
It worked perfectly with the SqlServer storage, but Hangfire.Redis.StackExchange does not seem to expose the queue name when it's queuing jobs.
context.BackgroundJob.Job.Queue
is alwaysnull
.Any suggestions?
Thank you!