我正在创建一个新的Azure WebJob项目 - 它似乎是一个可以作为Web作业运行的控制台应用程序的精美版本.
我希望这个工作能够根据时间表运行,但是在Main()方法中 - 见下文 - 微软为您host.RunAndBlock()提供了连续运行的工作.
如果我希望工作定期运行,我是否需要更改?
static void Main()
{
var host = new JobHost();
// The following code ensures that the WebJob will be running continuously
host.RunAndBlock();
}
Run Code Online (Sandbox Code Playgroud) 我有一个Azure WebJob项目,我在我的开发机器上本地运行.它正在侦听Azure Service Bus消息队列.什么都没有像主题,只是最基本的消息队列.
它多次接收/处理相同的消息,在收到消息时立即启动两次,然后在处理消息时间歇性地启动.
问题:
我正在使用异步函数,简单的注入器和自定义JobActivator,因此我的函数签名是:而不是静态void方法:
public async Task ProcessQueueMessage([ServiceBusTrigger("AnyQueue")] MediaEncoderQueueItem message, TextWriter log) {...}
Run Code Online (Sandbox Code Playgroud)
在工作中,它正在移动blob服务上的一些文件,并从媒体服务调用(和等待)媒体编码器.因此,虽然Web作业本身没有进行大量处理,但是需要相当长的时间(对于某些文件,这需要15分钟).
该应用程序正在启动,当我向队列发布消息时,它会响应.但是,一旦收到消息,它就会多次收到消息:
Executing: 'Functions.ProcessQueueMessage' - Reason: 'New ServiceBus message detected on 'MyQueue'.'
Executing: 'Functions.ProcessQueueMessage' - Reason: 'New ServiceBus message detected on 'MyQueue'.'
Run Code Online (Sandbox Code Playgroud)
此外,当任务正在运行时(我看到媒体服务功能的输出),它将从队列中获得另一个"副本".
最后,在任务完成后,它仍然间歇性地处理相同的消息.
触发后,生成3个XML文件,一旦完成,将其ftp到站点.
我有一个HTTP Trigger Azure功能,在运行时将构造3个XML文件并将它们保存到Azure存储Blob容器中.由于多个输出,以及需要控制输出路径/文件名,我使用
命令式绑定方法并使用IBinder outputBinder我的函数.这一切都很好.blob存储中输出路径的一个示例是export/2017-03-22/file-2017-03-22T12.03.02.54.xml.该文件位于包含日期的文件夹中,每个文件名都有时间戳以确保唯一性.
当生成所有3个文件时,我想触发另一个将这些文件sFTP到站点的功能.现在我最初认为我应该使用blob触发器,但我无法想象如何触发其文件名和路径是动态的输入.我不能在blob触发器文档中找到这样的例子.
那么我想我可以将HTTP触发器输出到声明性绑定,并将XML文件输出到outgoing我的blob触发器中可以查看的blob存储器中的容器中.这也有效,因为我的功能是消费计划,处理新blob可能有最多10分钟的一天.
因此,记录的备选方案是使用队列触发器.我可以输出到我的队列并让队列触发器正常,但是我如何将3个XML流传递给我的QueueTrigger函数?
我想作为后退,我可以发布一个可以包含构建的XML的Azure存储路径的对象,然后使用存储SDK获取流并使用它发布到FTP,但是它也会更高效将那些Storage Blob流作为输入传递给我的QueueTrigger?
在具有通用主机的 .NET Core 2.1 应用程序中使用 IConfigurationBuilder 时,我配置了 4 个源;但是在 ConfigureAppConfiguration 的范围之后,有 6 个来源。
在某些时候,我已经加载的 2 个附加源以导致 appsettings.Environment.json 值被隐藏的顺序第二次添加。我还尝试删除 hostsettings.json 配置并验证这不会影响到这一点。这是针对使用 WebjobsSDK 3.0 和 .Net Core 2.1 的 Azure Webjob
var builder = new HostBuilder()
.ConfigureHostConfiguration(configurationBuilder =>
{
//This is to do some basic host configuration and should only add 2 sources
configurationBuilder.SetBasePath(Directory.GetCurrentDirectory());
configurationBuilder.AddJsonFile("hostsettings.json", optional: true);
configurationBuilder.AddEnvironmentVariables(prefix: "APPSETTING_ASPNETCORE_");
})
.ConfigureAppConfiguration((hostContext, configurationBuilder) =>
{
//at this point there are 0 sources in the sources
IHostingEnvironment env = hostContext.HostingEnvironment;
configurationBuilder.SetBasePath(Directory.GetCurrentDirectory());
configurationBuilder.AddJsonFile("appSettings.json", optional: false, …Run Code Online (Sandbox Code Playgroud) 缺少升级到 Webjob V3 的参考
安装参考
“IWebJobsBuilder”不包含“AddTimers”的定义,并且找不到接受“IWebJobsBuilder”类型的第一个参数的可访问扩展方法“AddTimers”(您是否缺少 using 指令或程序集引用?)
我在使用新的0.3.0-beta WebJobs SDK的WebJob中有以下逻辑.当我的代码处理消息失败时,Azure仪表板会显示聚合异常(这是有意义的,因为这是异步).但是,它不会重试处理消息.
我能够找到的文档非常少,表明该消息应在失败后的10分钟内重试.新SDK不是这种情况吗?
public static Task ProcessMyMessageAsync(
[QueueTrigger(Config.MY_QUEUE)] string msg,
int dequeueCount,
CancellationToken cancellationToken)
{
var processor = Config.Container.GetInstance<IMessageProcessor>();
return processor.HandleJobAsync(msg, dequeueCount, cancellationToken);
}
Run Code Online (Sandbox Code Playgroud)
我得到的异常源于SQL Timeout异常(我的代码中针对SQL Azure的db查询):
System.AggregateException: System.AggregateException: One or more errors occurred.
---> System.Data.Entity.Core.EntityCommandExecutionException: An error occurred while executing the command definition. See the inner exception for details.
---> System.Data.SqlClient.SqlException: Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.
---> System.ComponentModel.Win32Exception: The wait operation timed out
Run Code Online (Sandbox Code Playgroud) 我有大量的Azure WebJob,它们都部署到单个Azure App Service,以及同一个Azure App Service上的网站。每个WebJob都使用WebJobs SDK和Microsoft.Web.WebJobs.Publish nuget包(我们是1.0.13版的最新版本)来打包它们以进行部署。以下是我们在CI构建(VSTS)中用于生成部署包的MSBuild参数:
/p:DeployOnBuild=true /p:PublishProfile=Release /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation=$(Build.StagingDirectory)
这将产生一个与“ Azure Web Service Deploy” VSTS任务正常工作的程序包(因为WebJobs可以作为WebJobs正常运行),这不是问题。
问题是.zip文件包复制了所有WebJob程序集。这些重复最终将其复制到Azure应用服务中。
每个WebJob软件包的.zip文件中的文件夹结构为:
- Content/[build agent full path]/
- app_data/jobs/continuous/[web job name]/[assembly files]
- bin/[assembly files]
Run Code Online (Sandbox Code Playgroud)
造成问题的原因有3个:
bin/[assembly files]其发布到App Service,因此它们与网站的程序集相互混合,这些程序集也已部署到同一App Service。那么,为什么Microsoft.Web.WebJobs.Publish包bin/[assembly files]中除了必需的之外又添加了app_data/jobs/continuous/[WebJobName]/[assembly files]?更重要的是,如何防止包装过程包括在内bin/[assembly files]?
我真的很讨厌不得不添加构建步骤来拆分压缩后的软件包,然后将它们放回去而又不会产生多余的垃圾,或者我不得不想出一种手工制作发布软件包的方法。您有1个工作,Microsoft.Web.WebJobs.Publish!:)
尝试按照@matthoneycutt关于Azure IoT Hub的教程,似乎Microsoft.Azure.WebHosts.JobHostConfiguration在Microsoft.Azure中的Microsoft.Azure.WebHosts.Host的3.0.0-beta5和3.0.0-rc1版本之间消失了。 WebHosts nuget 包?
在 Microsoft.Azure.WebHosts 3.0.0-rc1 中运行此代码的方法是什么?
var processorHost = new EventProcessorHost(hubName, consumerGroupName, iotHubConnectionString, storageConnectionString,storageContainerName);
processorHost.RegisterEventProcessorAsync<LoggingEventProcessor>().Wait();
var eventHubConfig = new EventHubConfiguration();
eventHubConfig.AddEventProcessorHost(hubName, processorHost);
var configuration = new JobHostConfiguration(storageConnectionString);
configuration.UseEventHub(eventHubConfig);
var host = new JobHost(configuration);
host.RunAndBlock();
Run Code Online (Sandbox Code Playgroud)
似乎与这篇文章相关,尽管在不同的上下文中
我已将 .NET(不是 .NET Core)WebJob 从 V2(工作正常)升级到 V3。我无法让它运行。我只是想让网络作业调用我根据这个 CRON 时间表编写的函数:“0 0 8,10,12,14,16,18,20 * * *”。它运行的网站也是 .NET,而不是 .NET Core。
我该怎么做呢?我只想要一个简单的工作 .NET 代码示例。我看到过这个问题New Azure WebJob Project - JobHostConfiguration/RunAndBlock在NuGet更新后丢失,这个例子https://github.com/Azure/azure-webjobs-sdk/blob/00686a5ae3b31ca1c70b477c1ca828e4aa754340/sample/SampleHost/Program.cs和这个文档https://learn.microsoft.com/en-us/azure/app-service/webjobs-sdk-how-to#triggers但没有一个有帮助。
c# asp.net azure-webjobs azure-webjobssdk azure-webjobs-triggered
我有这个功能
public class Functions
{
public Functions()
{
}
[FunctionName("httptriggertest")]
public async Task<IActionResult> HttpTriggerTest([HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "httptriggertest")] HttpRequest req,
ILogger log)
{
log.Log(LogLevel.Information, "Received request request");
return new OkObjectResult("HttpTriggerTest");
}
}
Run Code Online (Sandbox Code Playgroud)
并通过以下方式运行它:
public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebJobs(b =>
{
b.AddAzureStorageCoreServices()
.AddAzureStorage()
.AddHttp();
})
.ConfigureLogging((context, b) =>
{
b.SetMinimumLevel(LogLevel.Debug);
b.AddConsole();
})
.ConfigureAppConfiguration(b =>
{
b.AddCommandLine(args);
})
.UseConsoleLifetime();
}
Run Code Online (Sandbox Code Playgroud)
当我运行时dotnet run它启动正常(该函数由运行时发现)
info: Microsoft.Azure.WebJobs.Hosting.JobHostService[0]
Starting …Run Code Online (Sandbox Code Playgroud)