首页 > Web开发 > 详细

在ASP .NET CORE中使用 hangfire 分布式任务框架

时间:2020-05-12 21:45:00      阅读:319      评论:0      收藏:0      [点我收藏+]

AspNetCore.Hangfire.Extension

hangfire extension

Add Hangfire

 1  services.AddHangfire(config =>
 2             {
 3                 config.UseRedisStorage(
 4                     Configuration["RedisConnectionString"],
 5                     new RedisStorageOptions
 6                     {
 7                         Db = 7,
 8                         Prefix = "abc-sys"
 9                     });
10             });

 

Use Hangfire

    app.UseHangfireServer();
            app.UseHangfireDashboard("/hangfire", new DashboardOptions
            {
                Authorization = new[] { new HangfireAuthorizationFilter() },
                IgnoreAntiforgeryToken = true,
                AppPath = "/swagger/index.html",
                DashboardTitle = "Abc Sys Hangfire Dashboard"
            });
            app.AddOrUpdateJobs();

 

HangfireAuthorizationFilter

  /// <summary>
    /// HangfireAuthorizationFilter
    /// </summary>
    public class HangfireAuthorizationFilter : IDashboardAuthorizationFilter
    {
        /// <summary>
        /// no authorize
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public bool Authorize(DashboardContext context)
        {
            return true;
        }
    }

 

TestJob

  /// <summary>
    /// TestJob
    /// </summary>
    [SimpleJob(IsOpen = true, JobId = "TestJob", CronExpression = "0 0 8 * * ?")]
    public class TestJob : BaseRecurringJob
    {
        /// <summary>
        /// execute job
        /// </summary>
        /// <returns></returns>
        public override async Task Execute()
        {
            //todo job
        }
    }

 github url:https://github.com/cailin0630/AspNetCore.Hangfire.Extension

在ASP .NET CORE中使用 hangfire 分布式任务框架

原文:https://www.cnblogs.com/jiangyihz/p/12878020.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!