我如何在本地运行Azure WebJob

问题描述 投票:12回答:1

我想创建一个连续运行的WebJob,但首先我想尝试在本地运行它以进行调试。我正在使用Visual Studio 2015,并且正在运行Azure存储模拟器(可以在Visual Studio中运行Azure WebJobs的示例)。

[当我运行下面的命令时,它在new JobHost()行上失败:

异常:值不能为null。参数名称:方​​法

    static void Main()
    {
        var host = new JobHost();
        host.CallAsync(typeof(Functions).GetMethod("GetNextJob"));
        // The following code ensures that the WebJob will be running continuously
        host.RunAndBlock();
    }
    [NoAutomaticTriggerAttribute]
    public static async Task GetNextJob()
    {
        while(true)
        {
            try
            {
                var log = new Logger();
                log.WriteInfo("Getting next job to be run", 0, 0, "Brain");
                //Console.WriteLine("Getting new Job and putting to que");
            }
            catch(Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            await Task.Delay(TimeSpan.FromSeconds(5));
        }
    }

我什至可以在本地运行连续运行的作业吗?

c# azure azure-webjobs
1个回答
17
投票

Azure Web作业通常只是控制台应用程序。您可以像在调试,测试和运行任何其他控制台应用程序一样在本地运行它。我建议您先获取Azure WebJobs SDK并运行本教程Create a .NET WebJob in Azure App Service

© www.soinside.com 2019 - 2024. All rights reserved.