Azure WebJob,如果中止会如何通知?
(1)始终为服务启用可用性。 (2)SCM_COMMAND_IDLE_TIMEOUT = 2000。 WEBJOBS_IDLE_TIMEOUT = 2000。
答案 0 :(得分:0)
但是我是新手。你可以帮我解决这个问题,我可以把逻辑
您可以在Function.cs文件中添加逻辑。有关详细信息,请参阅详细步骤
<强>步骤:强>
1.跟随官方document创建一个webjob项目。
2.在项目中添加Functions.cs
using System.IO;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions;
using SendGrid;
public class Functions
{
//demo webjob trigger
public static void ProcessQueueMessage([QueueTrigger("queue")] string message, TextWriter log)
{
log.WriteLine(message);
}
// error monitor
public static void ErrorMonitor([ErrorTrigger("0:30:00", 10, Throttle = "1:00:00")]TraceFilter filter, [SendGrid] SendGridMessage message)
{
message.Subject = "WebJobs Error Alert";
message.Text = filter.GetDetailedMessage(5);
}
}
3.如果想使用ErrorTrigger和SendGrid,我们需要在Program.cs文件中对其进行配置。
static void Main()
{
var config = new JobHostConfiguration();
if (config.IsDevelopment)
{
config.UseDevelopmentSettings();
}
config.UseCore();
config.UseSendGrid(new SendGridConfiguration
{
ApiKey = "xxxxx",
FromAddress = new Email("emailaddress","name"),
ToAddress = new Email("emailaddress","name")
});
var host = new JobHost(config);
// The following code ensures that the WebJob will be running continuously
host.RunAndBlock();
}
4.如果我们想在本地测试它,我们需要在App Settings集合中添加存储连接字符串。
<connectionStrings>
<add name="AzureWebJobsStorage" connectionString="{storage connection string}" />
</connectionStrings>