简体   繁体   中英

How to automatically start Azure WebJob with TimeTrigger after recycle/restart WebApp

I am using a WebJob in an Azure WebApp. The job executes a method:

public static void ProcessQueue(
            [TimerTrigger("00:02:00")] TimerInfo timerInfo,
            [Queue("queue")] CloudQueue queue,
            [Table("processing")] CloudTable processingTable,
            TextWriter log)
{
    // do sth...
}

The TimeTrigger option came from Microsoft.Azure.WebJobs.Extensions .

I set the WebApp to run in "always on" mode .

But if I am doing a restart or change a application setting the WebApp does possibly, internally make a recycle? I think.

Because after this I am getting the following error:

[11/10/2016 08:22:24 > 36d12e: SYS ERR ] WebJob run failed due to: System.Threading.ThreadAbortException: Thread was being aborted. at Kudu.Core.Jobs.BaseJobRunner.RunJobInstance(JobBase job, IJobLogger logger, String runId, String trigger, ITracer tracer, Int32 port) at Kudu.Core.Jobs.TriggeredJobRunner.<>c__DisplayClass10_1.b__0(Object _)

So I tried to set a schedule on the WebJob and I also tried to paste a CRON schedule in the directory but nothing helped my out to bring the job to "running" after a reset/recycle.

Update 1
The content of my exe ( Main() )

JobHostConfiguration config = new JobHostConfiguration();
config.Tracing.ConsoleLevel = TraceLevel.Verbose;
config.Queues.MaxDequeueCount = 10;
config.UseCore();
config.UseTimers();
var host = new JobHost(config);
host.RunAndBlock();

Update 2
If I deploy as continous manually in Azure Portal everything is running as expected (Thanks mathewc). But this is a manually step ;). I am in a DevOps scenario everything will be build, created and deployed by the Visual Studio Team Services and there you cannot set any option to deploy the job as continous .

Based on the call stack you've shown, it looks like you may have incorrectly deployed your job as a triggered rather than continuous WebJob? When using the WebJobs SDK, you should deploy your WebJobs as continuous as described here .

Once running in continuous mode, you are correct that if you change an app setting or otherwise cause a restart, your WebJobs will also restart. However the internal scheduler for TimerTrigger will ensure the job continues to run on schedule when it comes back up.

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