我想知道Azure WebJobs SDK是否可以触发异步方法?目前我有一个如下所示的方法:
class Program
{
static void Main(string[] args)
{
var host = new JobHost();
host.RunAndBlock();
}
public static void ProcessStuff([QueueInput("myqueue")] string msg)
{
var tsk = ProcessStuffAsync(msg)
.ContinueWith(x => HandleAsyncError(x),
TaskContinuationOptions.OnlyOnFaulted);
tsk.Wait();
}
public static async Task ProcessStuffAsync(string msg)
{
// do some async stuff and await it
}
// other methods ...
}
Run Code Online (Sandbox Code Playgroud)
但是,我想知道我是否可以让JobHost知道调用我的异步方法呢?尝试在WebJobs中使用async/await时,没有大量的文档,如果可以的话,它会非常好.
我正在尝试在本地运行此测试...但WebJobs SDK不支持本地存储模拟器...
更新2014年4月7日:Victor的答案是正确的,但我确实想要展示你在WebJob中使用异步方法会看到什么(他们确实有效).
对于WebJob中的方法,如下所示:
public async static Task ProcessMessageAsync([QueueInput("testq2")] string message)
{
await Task.Delay(50);
Console.WriteLine("Processing Message Async...");
Console.WriteLine(message);
}
Run Code Online (Sandbox Code Playgroud)
您将在WebJobs日志中看到以下输出:
running in pid: …Run Code Online (Sandbox Code Playgroud) 我们有一个带有"暂存"部署插槽的Azure网站设置,我们使用连续的Azure WebJob来处理长时间运行的后台作业.看来,当您发布到网站(并包含WebJob二进制文件)时,如果先前已停止,WebJob将自动重新启动.
我们当前的部署过程如下所示:
是否有一个技巧(比如一个标志文件或其他东西)告诉WebJob在发布后不要启动?
我一直在梳理Powershell 命令,试图找出如何使用我当前部署的网站/ SQL数据库/存储帐户并将它们移动到自己的资源组中.
是否可以在资源组之间移动Azure"资源"?或者我是否总是需要创建新资源并将数据/代码迁移到这些新资源中?
我在使用新的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) 我希望我在这里遗漏了一些明显的东西......
这只发生在IE9中(图)
我正在使用KnockoutJS(2.1 RC)和JQuery(1.7.2)
我在页面上有一个输入元素(实际上很多),每当我点击"回车"键时,它就会触发click页面上第一个按钮元素的事件.