0

I have the following WebJob project where I'm trying to deploy a TimerTrigger WebJob function, however I cannot get it to run on a scheduled basis when deploying it via "Publish As Azure WebJob..." in Visual Studio 2017.

Program.cs

class Program
{
    static void Main()
    {
        var config = new JobHostConfiguration();

        if (config.IsDevelopment)
        {
            config.UseDevelopmentSettings();
        }

        config.UseTimers();

        var host = new JobHost(config);
        host.RunAndBlock();
    }
}

Functions.cs

public class Functions
{
        public static async Task ProcessAsync([TimerTrigger("0 */3 * * * *")] TimerInfo timerInfo, TextWriter log)
        {
              ...
        }
}

webjob-publish-settings.json

{
  "$schema": "http://schemastore.org/schemas/json/webjob-publish-settings.json",
  "webJobName": "TestWebJob",
  "runMode": "OnDemand"
}

Settings.job

{ "schedule": "0 */3 * * * *" }

The documentation for this is pretty non-existent, and it's baffling to why Azure supports Scheduled CRON TimerTrigger's but doesn't actually include them as an option when deploying.

Is this possible?

Davy-F
  • 123
  • 1
  • 2
  • 12

2 Answers2

1

If you have created a schedule webjob manually, I think you probably have found it will generate a settings.job to set the schedule.Then the SCHEDULE in the portal read the schedule and show it. And if you deploy a TimerTrigger webjob with VS2017, it won't generate this file because you have define the TimerTrigger function.

Then I did some tests to show it.Firstly I create a webjob with TimerTrigger and deploy it, it will show same result just like yours with n/a SCHEDULE. Then I kill the webjob process and upload a settings.job then refresh(not the refresh in in the portal) the page, then the SCHEDULE change to CRON expression. And if you delete the file, it will change back. enter image description hereenter image description here

As for the log, in my opinion it's also caused by the settings.job, if you have this file it will trigger this webjob every x minutes, and if you don't have it will trigger the function every x minutes in a webjob.

If you still have questions, please let me know.

George Chen
  • 13,703
  • 2
  • 11
  • 26
  • And if you use TimerTrigger to call a function , you could just deploy it as a continuous webjob, it still works. – George Chen Dec 14 '18 at 06:49
  • "As for the log, in my opinion it's also caused by the settings.job, if you have this file it will trigger this webjob every x minutes, and if you don't have it will trigger the function every x minutes in a webjob." Yep, this is the confusing part which should be documented more strongly. Thanks for the reply. – Davy-F Dec 14 '18 at 09:32
0

It seems that the above code is working. However, it runs completely differently to how you would imagine if you're familiar with running "Scheduled" WebJobs manually.

If you were to run them manually, you would usually see the Schedule at the top level, along with the Status updating every x minutes, etc:

WebJob

and you would also see the logs update at parent level, like so:

logs 1

However, when deploying it using the above method via Visual Studio 2017, you only ever get the WebJob running once for the duration of it's lifetime. As a result you would only ever get one parent log in the logs list too.

Though if you click into this, you will see individual logs for each scheduled function log:

function logs

Hopefully this will make sense for other people who are looking into setting up WebJobs :)

Davy-F
  • 123
  • 1
  • 2
  • 12