10

这个问题与这个问题有关:Running Azure WebJob without queue

我的场景:我只想每小时将一个文件写入 blob 存储,不需要任何队列系统。从前一个问题中,我得到了这段代码——它在第一次被触发时运行良好:

    [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();
    }

该网站以“AlwaysOn=true”运行,网络作业一直在“运行”,但现在调度程序抛出以下错误 - 没有任何反应:“由于作业已经在运行,因此无法开始新的运行。”

当前的结果是文件只被写入一次。如果我将“AlwaysOn”切换为 false,它“工作”,但它看起来很脏,因为没有 Always on the job 结果是“Aborted”。

4

1 回答 1

17

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.

于 2014-06-30T17:49:49.100 回答