question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Restarting/redeploy WebJob can cause DailySchedule to run twice

See original GitHub issue

Using <package id="Microsoft.Azure.WebJobs.Extensions" version="2.0.0-beta1-10332" targetFramework="net461" />

I have a DailySchedule running each day at 1 AM.

internal class BackupScheduler : DailySchedule
{
   public BackupScheduler() : base("01:00:00")
      {
      }
}

Sometimes the System.Timers.Timer will trigger the job before 1AM Azure WebJobs Dashboard

The status file written to azure-webjobs-hosts\timers\{hostid\{functionId}\status} Looks like this: {"Last":"2016-07-28T00:59:59.8690904+00:00","Next":"2016-07-28T01:00:00"}

The “Next” value is wrongly calculated to only a few milliseconds after the “Last” run. This is not a problem if the process keeps running, because (as I understand) the status file is only read on startup.

But if the WebJobs is redeployed or simply restarted. The CheckPastDueAsync in ScheduleMonitor will find that the timer IS past due and should be started.

I have fixed it locally with a hack; But this should be fixed in a proper way.

    internal class BackupScheduler : DailySchedule
    {
        public BackupScheduler() : base("01:00:00")
        {
        }

        public override DateTime GetNextOccurrence(DateTime currentTime)
        {
            TimeSpan threshold = TimeSpan.FromSeconds(10);
            DateTime nextOccurrence = base.GetNextOccurrence(currentTime);

            if (currentTime + threshold <= nextOccurrence)
            {
                return nextOccurrence;
            }
            return nextOccurrence.AddDays(1);
        }
    }

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:3
  • Comments:18 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
brettsamcommented, Jul 28, 2016

Yes! Thank you for the details @Thnslj, this helps enormously. I think I know what’s going on now – it’s possible for a timer to fire just before its ‘officially’ scheduled time (as we’ve written it in the blob). So if you’ve said you want it to run every day at midnight and we fire the timer just before midnight on the 1st, we’ll calculate that the next run should still be at midnight on the 1st – because that’s the next midnight that we see. It doesn’t affect anything if the site remains running but once it restarts, it consults the status blob and sees that it’s past due so it runs again.

I’ll look into a proper fix.

1reaction
mattwobertscommented, Aug 5, 2016

👍 All working for me now, awesome stuff!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Azure Scheduled Web job is triggering twice sometimes
We have an Azure WebJob which is scheduled to run at 8:00 AM UTC daily(CRON - 0 00 08 * * *).Most of...
Read more >
Azure Webjob - Webjob running twice at the same time
The workaround is to make sure the webjob run for a certain period of time (say at least 5 seconds assuming schedule interval...
Read more >
Azure WebJobs are awesome and you should start using ...
This is using a continuously running WebJob with the method above fired off via a queue trigger. In other words, when a new...
Read more >
WebJobs and Deployment Slots (Azure) - Simon Timms
Yes, both of these two jobs will be running at the same time. When you deploy to the deployment slot the webjob there...
Read more >
A pipeline is defined using a YAML file called bitbucket- ...
It will then execute the script on every action such as pull request, push request, manual trigger, and scheduled On Bitbucket console, go...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found