我打算使用连续的Azure WebJob来发送电子邮件和推送通知.我知道WebJobs会因各种原因不时启动和停止.这没关系,但我希望有机会在工作关闭前"清理".
这样我的WebJob就可以更新数据库记录的状态或删除每个批处理中已处理的队列项,这样下次作业运行时就不会发送重复的消息.
作为一个黑暗的镜头,我尝试将以下代码添加到我的C#控制台应用程序:
Console.CancelKeyPress += (object sender, ConsoleCancelEventArgs e) =>
{
e.Cancel = true;
program.keepRunning = false;
};
Run Code Online (Sandbox Code Playgroud)
然后我使用keepRunning bool来控制main while循环,并在while循环之外放置一个Console.Writeline("Exited Gracefully").但这似乎没有帮助.当我告诉作业停止时(使用我的Azure网站的Webjobs选项卡中的停止按钮),作业从列表中消失,并显示"无法停止作业:'JobName'." 在Azure门户中(位于页面底部).我没有看到WebJob日志中的"Exited Gracefully"文本.所以我把那个代码拿出来,因为它没有帮助.
所以,我正在寻找一个好方法,让我的WebJob被通知其秒数已经编号,并且需要按顺序获取其事务.
我在使用新的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) 我有一个Visual Studio 2013类库项目,目录结构如下:
\MyClassLibraryProject
\ExternalLibraries
3rdPartyLib.dll
\bin
\Debug
\Release
etc.
Run Code Online (Sandbox Code Playgroud)
在ExternalLibraries里面我复制了一些第三方程序集,然后我从项目中引用了它(Copy local = true).我编译项目,在我的Release目录中,我当然看到我的MyClassLibraryProject.dll和第三方DLL,如3rdPartyLib.dll等.到目前为止很好.
然后我有另一个项目(控制台应用程序 - Azure webjob),我从中添加了对\ MyClassLibraryProject\bin\Release\MyClassLibraryProject.dll(Copy local = true)的引用.它看起来像这样:
\MyWebjob
\bin
\Debug
MyWebJob.exe
MyClassLibraryProject.dll
3rdPartyLib.dll
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,当我添加对MyClassLibraryProject.dll的引用(使用Copy local = true)时,它还复制了它的依赖程序集3rdPartyLib.dll.目前很好.
但是,将webjob项目发布到Azure时(右键单击"项目","发布..."),不会部署3rdPartyLib.dll .结果,webjobs仪表板抱怨它无法找到,当然webjob不会执行.
这个用户是错误还是其他什么?
我正在运行Azure webjob和Azure webapp.作业定期运行,并且需要在webapp中完成作业.我如何在那里得到结果?
我尝试使用WCF,netNamedPipeBinding但由于Azure webapps没有启动任务,因此无法将net.pipe绑定添加到IIS网站,也无法启用net.pipe协议.
我现在有一个工作,basicHttpBinding但这个绑定暴露给我绝对不想要的整个互联网.我只想在同一台机器上运行的webjob和webapp之间进行机器本地通信.
更正:我认为我在Azure上工作但事实并非如此.在Azure上运行时,我从webjob收到错误:( An attempt was made to access a socket in a way forbidden by its access permissions 127.0.0.1:80使用basicHttpBinding).可能webapp有一个我不知道的内部端口号.
刚刚安装了Visual Studio 2017 15.3的预览版,但我仍然没有看到在.NET Core中创建WebJobs的方法.这是否可用 - 即使是预览版或测试版 - 还是没有?
PS:这不是主持人建议的重复问题.我只是说在另一篇文章中提出的建议不起作用.
在执行右键单击项目时获取以下消息 - >调试 - >启动新实例.
[1/7/2018 6:48:54 AM]发生ScriptHost错误[1/7/2018 6:48:54 AM]执行HTTP请求:{[1/7/2018 6:48:54 AM] Microsoft .Azure.WebJobs.Host:错误索引方法'TestFilesIngestJobs.RunScheduleAsync'.Microsoft.Azure.WebJobs.Host:无法绑定参数'log'以键入TraceWriter.确保绑定支持参数Type.如果您正在使用绑定扩展(例如ServiceBus,Timers等),请确保您已在启动代码中调用扩展的注册方法(例如config.UseServiceBus(),config.UseTimers()等).[1/7/2018 6:48:54 AM]"requestId":"dbb282d7-44e2-44b4-907e-877beac9da2d",[1/7/2018 6:48:54 AM]错误索引方法'MasterDataFilesIngestJobs.RunScheduleAsync' [1/7/2018 6:48:54 AM]"方法":"GET",
我在 Azure 门户中的暂存槽中使用自动部署来部署 Webjob,但问题是此 webjob 在部署后直接运行,它可能会导致主槽 webjob 和暂存 webjob 之间出现混淆。
有没有办法在不运行 webjob 的情况下部署它,除非我启动它并交换插槽?
我有一个简单的 Azure WebJobs ServiceBusTrigger,看起来像
public static async void ProcessQueueMessage([ServiceBusTrigger("myqueuename")] String json, TextWriter log) { ... }
Run Code Online (Sandbox Code Playgroud)
不幸的是,它无法将 JSON 反序列化为 XML(不足为奇)。我检查了有效负载并确认它只是一个 UTF-8 编码的字节数组。我有两个问题。
堆栈跟踪:
System.InvalidOperationException: Exception binding parameter 'json' ---> System.Runtime.Serialization.SerializationException: There was an error deserializing the object of type System.String. The input source is not correctly formatted. ---> System.Xml.XmlException: The input source is not correctly formatted.
at System.Xml.XmlExceptionHelper.ThrowXmlException(XmlDictionaryReader reader, String res, String arg1, String arg2, String arg3)
at System.Xml.XmlBufferReader.ReadValue(XmlBinaryNodeType nodeType, ValueHandle value)
at System.Xml.XmlBinaryReader.ReadNode() …Run Code Online (Sandbox Code Playgroud) 场景:生产者向存储队列发送消息,一个WebJobs在QueueTrigger上处理该消息,每条消息只能处理一次,可以有多个WebJob实例。
我一直在谷歌搜索,从我读过的内容来看,我需要编写处理消息的函数以使其具有幂等性,因此消息不会被处理两次。我还读到消息的默认租用时间为 10 分钟。
我的问题是,当在一个 WebJob 实例上触发 QueueTrigger 时,它是否设置了消息的租用时间,以便另一个 WebJob 无法获取相同的消息?如果是这样,为什么我需要考虑消息可以被处理两次的可能性?还是我误解了这一点?
我想在作为Service Fabric应用程序运行的无状态服务中使用WebJob SDK。不幸的是,我无法使其正常运行。下面是重现该问题的测试代码的一部分。永远不会调用“ ProcessMethod”。触发函数“ ProcessNotificationsInQueue”也永远不会执行(是的,队列中有项目)。尽管该应用程序仍在运行,但在Service Fabric资源管理器中将其“运行状况”设置为“错误”。
DashboardConnectionString和StorageConnectionString都具有正确的值。
当它在控制台应用程序或WorkerRole中运行时,我没有看到非常相似的代码有任何问题。
我想念什么吗?是否有人已经在Service Fabric应用程序中成功使用了WebJob SDK?
public sealed class TestStatelessService : StatelessService
{
public TestStatelessService(StatelessServiceContext context)
: base(context)
{ }
/// <summary>
/// Optional override to create listeners (e.g., TCP, HTTP) for this service replica to handle client or user requests.
/// </summary>
/// <returns>A collection of listeners.</returns>
protected override IEnumerable<ServiceInstanceListener> CreateServiceInstanceListeners()
{
return new ServiceInstanceListener[0];
}
/// <summary>
/// This is the main entry point for your service instance.
/// </summary>
/// <param name="cancellationToken">Canceled …Run Code Online (Sandbox Code Playgroud)