Skip to content

Early run resulting in duplicate execution of the job #327

@RShergold

Description

@RShergold

Describe the bug
Jobs are being run a fraction of a second early resulting in duplicate execution of the job.

I am creating a single job with

services.AddNCronJob(options =>
{
    var timeZone = TimeZoneInfo.FindSystemTimeZoneById("GMT Standard Time");
    options.AddJob<UnreadMessageEmailJob>(job =>
    {
        job.WithCronExpression("17 12 * * *", timeZone);
    });
});

and then

    var app = builder.Build();

    await app.UseNCronJobAsync();
    await app.RunAsync();

Current behavior
In my logs I can see the job is consumed a fraction of a second early meaning it schedules the next job for the exact same time as the current job.

Image

Then after the first job has run...

Image

This results in two duplicate jobs with different correlation IDs being run back to back

Expected behavior
For the job to be run on or after the time defined in the cron expression.

When removing and adding the next job is it possible to check the date time of the two to make sure we are not adding the same time we just removed?

The app is running on an IIS server. I'm not sure if there is some kind of strange configuration on our server causing this issue as I do not have direct access to it.

Version information

  • NCronJobVersion: 4.7.0
  • .NET runtime version: net8.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingquestionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions