gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-30 00:38:59 30 4
gpt4 key购买 nike

当 Azure WebJobs 因任何原因停止或重新启动时,主机控制台进程终止之前有 5 秒的默认宽限期。显然,可以通过在将 WebJob 发布到 Azure 时包含“settings.job”文件来增加此时间段,如 explained here 。不幸的是,我无法让它在我的网站上工作,并且关闭时间始终 5 秒,尽管这是发布到设置为“始终开启”的基本应用服务的连续 WebJob。

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

class Program
{
static void Main()
{
var host = new JobHost();
host.RunAndBlock();
}
}

我的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.");
}
}

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

{ "stopping_wait_time": 60 }

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

Kudu screenshot

但是,如果我查看链接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":{
}
}

因此,当我从 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

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

为什么“settings.job”文件被忽略?

最佳答案

问题是您的 settings.job 文件有两组 UTF-8 BOM,这是非常不寻常的并且会导致解析器崩溃。

具体来说,它的开头有以下序列(使用十六进制编辑器查看):EF BB BF EF BB BF。通常,UTF-8 BOM 就是 EF BB BF

您使用的是什么编辑器导致了这个问题?

无论如何,一旦你解决了这个问题,它应该可以正常工作。

关于c# - 为什么我的 Azure WebJobs "settings.job"文件被忽略?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36695607/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com