Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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".

like image 513
Robert Muehsig Avatar asked Jun 30 '14 09:06

Robert Muehsig


1 Answers

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.

like image 83
Victor Hurdugaci Avatar answered Sep 18 '22 13:09

Victor Hurdugaci