marcoCasamento / Hangfire.Redis.StackExchange

HangFire Redis storage based on original (and now unsupported) Hangfire.Redis but using lovely StackExchange.Redis client
Other
448 stars 108 forks source link

Library does not expose job queue for filters #137

Closed Lexy2 closed 4 months ago

Lexy2 commented 4 months ago

Hi there!

Thank you for the port.

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.

Any suggestions?

Thank you!

marcoCasamento commented 4 months ago

I believe this is linked to #138 and would be solved with it