HangfireIO / HangfireIO/Hangfire

Recurrent job executes on app service restart or execution time update

Open
#1,373 4 comments 0 reactions 0 assignees View on GitHub
t: question
Dominant language
C#
Stars
10.1k
Forks
1.8k
Avg merge
1h 19m
Merged PRs (30d)
1

Description

Hi,

I must be doing something wrong and trying to understand what exactly.

So I have a simple recurrent job updated on startup (ASP .NET Core hosted on Azure) in the following way:

`recurringJobManager.AddOrUpdate(Id, Job.FromExpression(s => s.RunAsync()), cronExpression, DateTimeHelper.MoscowTimeZoneInfo);`

The `cronExpression` is normally `Cron.Daily(16, 30);` but sometimes I change it to another time and deploy the project. Immediately after startup the job gets executed and it doesn't update the `NextExecution` field so I have to manually disable Hangfire to avoid double execution.

I've just tried to update the `NextExecution` field manually by setting a point in future and had the job immediately executed as well.

What am I doing wrong? I only want the job to be executed at a specific point in time rather than being affected by site deployment/startup/updating Cron expression etc.

Thanks in advance.

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the reported behavior around RecurringJobManager.AddOrUpdate, including app startup, a changed cronExpression, and manual NextExecution updates. Trace why the recurring job executes immediately and whether NextExecution is recalculated. Done means the job remains scheduled for its configured time across restart and schedule updates, with regression coverage for these cases.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.