EventFlow icon indicating copy to clipboard operation
EventFlow copied to clipboard

Possible bugs in HangfireJobScheduler

Open hainguyenthanh opened this issue 6 months ago • 1 comments

I'm using EventFlow v1.2.1 together with Hangfire and PostgreSQL. When the application scheduled a job using await jobScheduler.ScheduleAsync(job, runAt, cancellationToken) with runAt of 90 days in the future, the job executed immediately instead of executing at runAt. Reviewing the source code of the HangfireJobScheduler's ScheduleAsync method, I see that if _queueName is null, the job is enqueued by calling _backgroundJobClient.Enqueue(ExecuteMethodCallExpression(jobDefinition, json)) instead of calling _backgroundJobClient.Schedule(). As a result, the runAt argument is not passed to the Hangfire background job. And reviewing the Hangfire's _backgroundJobClient.Enqueue extension method, I see that the method enqueues to job to be executed immediately. This behaviour matches the issue I saw in my application.

In summary, calling _backgroundJobClient.Enqueue without using the runAt argument causes the Hangfire job to execute immediately.

Moreover, there could be the same bug in the HangfireJobScheduler's ScheduleAsync(IJob job, TimeSpan delay, CancellationToken cancellationToken) method.

Image

hainguyenthanh avatar Jun 03 '25 05:06 hainguyenthanh

As a workaround, a queue name can be specified in the configuration, e,g.

EventFlowOptions.New(services)
    .UseHangfireJobScheduler(opt => opt.UseQueueName("default"))
...

When a queue name is specified, ScheduleAsync will call _backgroundJobClient.Schedule() instead of _backgroundJobClient.Enqueue().

hainguyenthanh avatar Jun 03 '25 08:06 hainguyenthanh

Hello there!

We hope you are doing well. We noticed that this issue has not seen any activity in the past 90 days. We consider this issue to be stale and will be closing it within the next seven days.

If you still require assistance with this issue, please feel free to reopen it or create a new issue.

Thank you for your understanding and cooperation.

Best regards, EventFlow

github-actions[bot] avatar Sep 01 '25 09:09 github-actions[bot]

Hello there!

This issue has been closed due to inactivity for seven days. If you believe this issue still needs attention, please feel free to open a new issue or comment on this one to request its reopening.

Thank you for your contribution to this repository.

Best regards, EventFlow

github-actions[bot] avatar Sep 09 '25 09:09 github-actions[bot]

Sorry for the delay. Looking at this now

rasmus avatar Oct 11 '25 11:10 rasmus