在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

  /// 
    /// HangfireAuthorizationFilter
    /// 
    public class HangfireAuthorizationFilter : IDashboardAuthorizationFilter
    {
        /// 
        /// no authorize
        /// 
        /// 
        /// 
        public bool Authorize(DashboardContext context)
        {
            return true;
        }
    }

 

TestJob

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

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

你可能感兴趣的:(在ASP .NET CORE中使用 hangfire 分布式任务框架)