简体   繁体   中英

Why isn't my Azure WebJob scheduled?

I have an ASP.NET MVC5 application running as an App Service in Azure and want to schedule a WebJob to execute a console app every hour.

In the console application I have webjob-publish-settings.json file defined as:

{
  "$schema": "http://schemastore.org/schemas/json/webjob-publish-settings.json",
  "webJobName": "EpisodeUpdater",
  "startTime": "2017-05-01T00:00:00-08:00",
  "endTime": "2020-06-01T00:00:00-08:00",
  "jobRecurrenceFrequency": "Hour",
  "interval": 1,
  "runMode": "Scheduled"
}

When I look in the Azure portal the type of WebJob appears to be set as Triggered - the job will run successfully when I start it manually but it doesn't execute every hour.

WebJobs

WebJob属性

Can anyone see why the WebJob isn't scheduled properly?

In a way there are no Scheduled jobs. A scheduled WebJob is just an On-demand/Triggered WebJob that is triggered by a timer. Now this timer can be Azure Scheduler (which is what VS tooling used to create) or the built-in scheduler in Kudu.

To use the built-in scheduler, you create file called settings.job in the root of the project and have this as the content:

{
    "schedule": "0 0 * * * *"
}

That will run it every hour. It uses CRON expressions, in this case defining it should run always when seconds and minutes are zero. Now this does require Always On to be on in the app.

Documentation: https://docs.microsoft.com/en-gb/azure/app-service/web-sites-create-web-jobs#CreateScheduledCRON

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM