为什么我的Azure WebJobs"settings.job"文件被忽略?

Ste*_*nds 4 c# azure azure-webjobs

当Azure WebJobs因任何原因停止或重新启动时,在主机控制台进程终止之前,默认宽限期为5秒.显然,可以通过在WebJob发布到Azure时将"settings.job"文件包含在内来增加此时间段,如此处所述.不幸的是,我无法让这个工作用于我的网站,关机时间总是 5秒,尽管这是一个连续的WebJob,发布到设置为"Always On"的基本应用服务.

根据链接中的示例代码,我的Program.cs如下所示:

class Program
{
    static void Main()
    {
        var host = new JobHost();
        host.RunAndBlock();
    }
}
Run Code Online (Sandbox Code Playgroud)

和我的Functions.cs看起来像这样:

public class Functions
{
    public static async Task ProcessQueueMessageAsync(
        [QueueTrigger("testq")] string message, TextWriter log,
        CancellationToken cancellationToken)
    {
        Console.WriteLine("Function started.");
        try
        {
            await Task.Delay(TimeSpan.FromMinutes(10), cancellationToken);
        }
        catch (TaskCanceledException)
        {
            Shutdown().Wait();
        }
        Console.WriteLine("Function completed succesfully.");
    }

    private static async Task Shutdown()
    {
        Console.WriteLine("Function has been cancelled. Performing cleanup ...");
        await Task.Delay(TimeSpan.FromSeconds(30));
        Console.WriteLine("Function was cancelled and has terminated gracefully.");
    }
}
Run Code Online (Sandbox Code Playgroud)

我已将settings.job文件添加到项目中,并在Visual Studio中的属性中将其设置为"始终复制".该文件的内容如下:

{ "stopping_wait_time": 60 }
Run Code Online (Sandbox Code Playgroud)

WebJob随网站发布.通过使用Kudu工具并转到调试控制台,我可以验证"settings.job"文件是否被复制到与WebJob主机可执行文件相同的位置:

Kudu截图

但是,如果我查看链接,https://xxx.scm.azurewebsites.net/api/continuouswebjobs则返回的JSON根本不包含任何设置:

{
    "status":"Stopped",
    "detailed_status":"f9e13c - Stopped\r\n",
    "log_url":"https://...",
    "name":"WebJobTest",
    "run_command":"WebJobTest.exe",
    "url":"https://...",
    "extra_info_url":"https://...",
    "type":"continuous",
    "error":null,
    "using_sdk":true,
    "settings":{
    }
}
Run Code Online (Sandbox Code Playgroud)

因此,当我从Azure门户停止WebJob时,我在日志中最终得到类似的东西:

[04/18/2016 12:53:12 > f9e13c: SYS INFO] Run script 'WebJobTest.exe' with script host - 'WindowsScriptHost'
[04/18/2016 12:53:12 > f9e13c: SYS INFO] Status changed to Running
[04/18/2016 12:53:13 > f9e13c: INFO] Found the following functions:
[04/18/2016 12:53:13 > f9e13c: INFO] WebJobTest.Functions.ProcessQueueMessageAsync
[04/18/2016 12:53:13 > f9e13c: INFO] Job host started
[04/18/2016 13:01:58 > f9e13c: INFO] Executing: 'Functions.ProcessQueueMessageAsync' - Reason: 'New queue message detected on 'testq'.'
[04/18/2016 13:01:58 > f9e13c: INFO] Function started.
[04/18/2016 13:02:47 > f9e13c: SYS INFO] Status changed to Disabling
[04/18/2016 13:02:53 > f9e13c: SYS INFO] Detected WebJob file/s were updated, refreshing WebJob
[04/18/2016 13:02:53 > f9e13c: SYS INFO] Status changed to Stopping
[04/18/2016 13:02:53 > f9e13c: INFO] Function has been cancelled. Performing cleanup ...
[04/18/2016 13:02:58 > f9e13c: ERR ] Thread was being aborted.
[04/18/2016 13:02:58 > f9e13c: SYS INFO] WebJob process was aborted
[04/18/2016 13:02:58 > f9e13c: SYS INFO] Status changed to Stopped
Run Code Online (Sandbox Code Playgroud)

请注意"状态已更改为停止"和"线程正在中止"之间的标准5秒间隔.

为什么忽略"settings.job"文件?

Dav*_*bbo 7

问题是,你的settings.job文件有2套UTF-8 BOM,这是极不寻常,并抛出了解析器.

具体地,它具有在开始下面的序列(使用十六进制编辑器视图): EF BB BF EF BB BF.通常,UTF-8 BOM就是EF BB BF.

您使用的是什么编辑器?

在任何情况下,一旦你修复它,它应该工作正常.