简体   繁体   中英

Scheduled Azure WebJob but NoAutomaticTrigger-Method not invoked

This question is related to this one: Running Azure WebJob without queue

My scenario: I just want to write a file each hour into the blob storage and don't need any queue system. From the former question I got this code - which worked fine the first time it is triggered:

    [NoAutomaticTrigger]
    public static void DoWork([Blob("container/foobar.txt")] TextWriter writer)
    {
        writer.Write("Hello World " + DateTime.Now.ToShortTimeString())"
    }

    static void Main()
    {
        JobHost host = new JobHost();
        host.Call(typeof(Program).GetMethod("DoWork"));

        host.RunAndBlock();
    }

The website is running with "AlwaysOn=true" and the webjob is "Running" all the time but now the scheduler throws following error - and nothing happens: "Cannot start a new run since job is already running."

The current result is that the file is only written once. If I switch "AlwaysOn" to false it "works", but it seems dirty because without the Always on the job result is "Aborted".

A job marked as "on demand" must complete. In your case, the problem is the RunAndBlock call at the end. If you call that method, the console app never stops (that's why the job "is already running") because RunAndBlock is basically a while(true) loop.

RunAndBlock should be used only for continuous jobs.

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