预定的.NET WebJob V3示例 [英] Scheduled .NET WebJob V3 example

查看:127
本文介绍了预定的.NET WebJob V3示例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经将我的.NET(不是.NET Core)WebJob从V2(工作正常)升级到了V3.我无法使其运行.我只希望webjob调用我根据此CRON时间表编写的函数:"0 0 8,10,12,14,16,18,20 * * *".运行的网站也是.NET,而不是.NET Core.

I've upgraded my .NET (not .NET Core) WebJob from V2 (which was working fine) to V3. I'm having trouble getting it to run. I just want the webjob to call a function I've written according to this CRON schedule: "0 0 8,10,12,14,16,18,20 * * *". The website it's running with is .NET also, not .NET Core.

我该怎么做?我只想要一个简单的工作.NET代码示例.我已经看到了这个问题新Azure WebJob项目-JobHostConfiguration/RunAndBlock NuGet更新后丢失,并且此示例 https://github.com/Azure/azure-webjobs-sdk/blob/00686a5ae3b31ca1c70b477c1ca828e4aa754340/sample/SampleHost/Program.cs 和此文档

How do I do this? I just want a simple working .NET code sample. I've seen this question New Azure WebJob Project - JobHostConfiguration/RunAndBlock missing after NuGet updates and this example https://github.com/Azure/azure-webjobs-sdk/blob/00686a5ae3b31ca1c70b477c1ca828e4aa754340/sample/SampleHost/Program.cs and this documentation https://docs.microsoft.com/en-us/azure/app-service/webjobs-sdk-how-to#triggers but none of it is helpful.

推荐答案

.Net webjob或.Net Core webjob的使用实际上几乎相同,导致3.0 sdk针对.NET标准2.0.我用Microsoft.Azure.WebJobs -version 3.0.4Microsoft.Azure.WebJobs.Extensions -version 3.0.1进行了测试,我认为您的TimerTrigger无法正常工作,因为您丢失了对AddTimers扩展方法的调用.您可以在此处找到说明:

Actually the use of .Net webjob or .Net Core webjob are almost same, cause the 3.0 sdk targets .NET standard 2.0. I test with Microsoft.Azure.WebJobs -version 3.0.4 and Microsoft.Azure.WebJobs.Extensions -version 3.0.1, i think your TimerTrigger doesn't work cause you lost call the AddTimers extension methods. You could find the description here:Binding types.

我使用的其他软件包:

Microsoft.Extensions.Logging -version 2.2.0
Microsoft.Extensions.Logging.Console -version 2.2.0

这是我的main方法:

using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Hosting;
namespace ConsoleApp20
{
class Program
{
    static void Main(string[] args)
    {
        var builder = new HostBuilder();
        builder.ConfigureWebJobs(b =>
        {
            b.AddAzureStorageCoreServices();
            b.AddTimers();
        });
        builder.ConfigureLogging((context, b) =>
        {
            b.AddConsole();

        });
        var host = builder.Build();
        using (host)
        {
            host.Run();
        }
    }
}
}

这是我的Functions.cs:

public static void Run([TimerTrigger("0 0 8,10,12,14,16,18,20 * * *")]TimerInfo myTimer, ILogger log)
    {

        log.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}");
    }

并使用appsettings.json(不要忘记将Copy to Output Directory设置为Copy always)来配置存储连接字符串.

And use a appsettings.json(Don't forget set the Copy to Output Directory to Copy always) to configure the storage connection string.

这是结果:

这篇关于预定的.NET WebJob V3示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆