zoukankan      html  css  js  c++  java
  • 在ASP .NET CORE中使用 hangfire 分布式任务框架

    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

  • 相关阅读:
    Longest Common Substring
    未完成 Anagrams
    strStr
    vim的学习笔记
    Compare Strings
    Two Strings Are Anagrams
    KMP算法
    [ 力扣活动0314 ] 300. 最长上升子序列
    [ 力扣活动0317 ] 1160. 拼写单词
    [ 力扣活动0313 ] 169. 多数元素
  • 原文地址:https://www.cnblogs.com/jiangyihz/p/12878020.html
Copyright © 2011-2022 走看看