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

相关文章:

  • 2021-12-31
  • 2021-09-13
  • 2021-07-26
  • 2022-12-23
  • 2022-12-23
  • 2022-01-05
  • 2022-01-09
猜你喜欢
  • 2021-10-29
  • 2021-09-18
  • 2022-12-23
  • 2022-01-02
  • 2022-01-10
  • 2021-05-27
相关资源
相似解决方案