为什么我的Azure WebJobs" settings.job"文件被忽略? [英] Why is my Azure WebJobs "settings.job" file being ignored?
问题描述
在Azure的WebJobs被暂停或重启不管是什么原因,有5秒的默认宽限期结束主机控制台过程之前。显然,可以通过包括与WebJob一个settings.job文件发布时天青,作为此处解释。不幸的是,我不能得到这个为我的网站工作,并停止期间的总是的5秒,尽管这是发布到被设置为永远在线基本应用服务连续WebJob。
When Azure WebJobs are stopped or restarted for whatever reason, there is a default grace period of 5 seconds before the host console process is terminated. Apparently it is possible to increase this time period by including a "settings.job" file with the WebJob when it is published to Azure, as explained here. Unfortunately I cannot get this to work for my website, and the shutdown period is always 5 seconds, despite this being a continuous WebJob that is published to a Basic App Service that is set to "Always On".
根据从链接样本code,我的的Program.cs 是这样的:
As per the sample code from the link, my Program.cs looks like this:
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属性我已经将它设置为复制总是。该文件的内容如下:
I have added a settings.job file to the project, and in its Properties in Visual Studio I have set it to "Copy always". The content of the file is as follows:
{ "stopping_wait_time": 60 }
该WebJob发布的网站。通过使用捻工具和去调试控制台我可以验证settings.job文件正在被整个复制到相同的位置WebJob主机可执行文件:
The WebJob is published with the website. By using the Kudu tools and going to the debug console I can verify that the "settings.job" file is being copied across to the same location as the WebJob host executable:
不过,如果我看的链接 https://xxx.scm.azurewebsites.net/api/continuouswebjobs
返回的JSON不包括任何设置都:
However, if I look at the link https://xxx.scm.azurewebsites.net/api/continuouswebjobs
the returned JSON does not include any settings at all:
{
"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:
Consequently, when I stop the WebJob from the Azure portal I end up with something like this in the logs:
[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秒的差距状态改为停止和线程已被中止。
Note the standard 5 second gap between "Status changed to Stopping" and "Thread was being aborted".
为什么settings.job文件被忽略?
Why is the "settings.job" file being ignored?
推荐答案
的问题是,你的 settings.job
文件中有两个套UTF-8 BOM,这是极不寻常,并抛出了解析器。
The problem is that your settings.job
file has two sets of UTF-8 BOM, which is highly unusual and throws off the parser.
具体而言,它的开头下列顺序(使用十六进制编辑器视图): EF BB BF EF BB BF
。通常情况下,UTF-8 BOM就是 EF BB BF
。
Specifically, it has the following sequence at the beginning (view using a hex editor): EF BB BF EF BB BF
. Normally, the UTF-8 BOM is just EF BB BF
.
什么编辑器,你使用的原因造成的?
What editor are you using that caused that?
在任何情况下,一旦你修复时,它应该工作正常。
In any case, once you fix that up, it should work fine.
这篇关于为什么我的Azure WebJobs" settings.job"文件被忽略?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!