Open Closed

Abp-820-Hangfire-errror-with-redis-db #7458


User avatar
0
cetin.sahin created
  • ABP Framework version: v8.2.0
  • UI Type: Blazor Server
  • Database System: EF Core (SQL Server
  • Tiered (f): yes

We use redis for hangfire database ; we add HttpApi.Host project this code

private void ConfigureHangfire(ServiceConfigurationContext context, IConfiguration configuration) { string redisConfig = configuration["Redis:HangfireRedis"].ToString();

context.Services.AddHangfire(config =>
{

    config.UseRedisStorage(redisConfig, new RedisStorageOptions()
    {
        Prefix = "hangfire:app1:",
          Db = 8,
    });
    //config.UseRecurringJobAdmin(typeof(StartupBase).Assembly;


});
context.Services.AddHangfireServer(options =>
{
    options.ServerName = "EnzimWeb";

});

}

But we get error

2024-07-04 16:34:28.486 +03:00 [FTL] Host terminated unexpectedly! Volo.Abp.AbpInitializationException: An error occurred during the initialize Volo.Abp.Modularity.OnApplicationInitializationModuleLifecycleContributor phase of the module Volo.Abp.AuditLogging.AbpAuditLoggingApplicationModule, Volo.Abp.AuditLogging.Application, Version=8.2.0.0, Culture=neutral, PublicKeyToken=null: Cannot convert period: 86400000 to cron expression, use HangfireBackgroundWorkerBase to define worker. See the inner exception for details. ---> Volo.Abp.AbpException: Cannot convert period: 86400000 to cron expression, use HangfireBackgroundWorkerBase to define worker at Volo.Abp.BackgroundWorkers.Hangfire.HangfireBackgroundWorkerManager.GetCron(Int32 period) at Volo.Abp.BackgroundWorkers.Hangfire.HangfireBackgroundWorkerManager.AddAsync(IBackgroundWorker worker, CancellationToken cancellationToken) at Volo.Abp.AuditLogging.AbpAuditLoggingApplicationModule.OnApplicationInitializationAsync(ApplicationInitializationContext context) at Volo.Abp.Modularity.OnApplicationInitializationModuleLifecycleContributor.InitializeAsync(ApplicationInitializationContext context, IAbpModule module) at Volo.Abp.Modularity.ModuleManager.InitializeModulesAsync(ApplicationInitializationContext context) --- End of inner exception stack trace --- at Volo.Abp.Modularity.ModuleManager.InitializeModulesAsync(ApplicationInitializationContext context) at Volo.Abp.AbpApplicationBase.InitializeModulesAsync() at Volo.Abp.AbpApplicationWithExternalServiceProvider.InitializeAsync(IServiceProvider serviceProvider) at Microsoft.AspNetCore.Builder.AbpApplicationBuilderExtensions.InitializeApplicationAsync(IApplicationBuilder app) at EnzimWeb.Program.Main(String[] args) in F:\azure\enzimiber\src\EnzimWeb.HttpApi.Host\Program.cs:line 38


7 Answer(s)
  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    This is a known problem, we will fix it in the next patch version,

    This is a temporary solution

    [Dependency(ReplaceServices = true)]
    [ExposeServices(typeof(IBackgroundWorkerManager), typeof(HangfireBackgroundWorkerManager))]
    public class MyHangfireBackgroundWorkerManager: HangfireBackgroundWorkerManager
    {
        public MyHangfireBackgroundWorkerManager(IServiceProvider serviceProvider) : base(serviceProvider)
        {
        }
    
    
        protected override string GetCron(int period)
        {
            var time = TimeSpan.FromMilliseconds(period);
            string cron;
    
            if (time.TotalSeconds <= 59)
            {
                cron = $"*/{time.TotalSeconds} * * * * *";
            }
            else if (time.TotalMinutes <= 59)
            {
                cron = $"*/{time.TotalMinutes} * * * *";
            }
            else if (time.TotalHours <= 23)
            {
                cron = $"0 */{time.TotalHours} * * *";
            }
            else if(time.TotalDays <= 31)
            {
                cron = $"0 0 0 1/{time.TotalDays} * *";
            }
            else
            {
                throw new AbpException(
                    $"Cannot convert period: {period} to cron expression, use HangfireBackgroundWorkerBase to define worker");
            }
    
            return cron;
        }
    }
    
    
  • User Avatar
    0
    cetin.sahin created

    Our project is tiered. Which project will we add this code?

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Add to all projects where hangfire is installed

  • User Avatar
    0
    cetin.sahin created

    In our project, we were using MSSQL Server 2012 for the Hangfire database. However, with ABP 8.2.0, Hangfire 1.8.14 NuGet package is being used. Although we tried to set SetDataCompatibilityLevel(110) with Hangfire 1.8.14, we encountered an error. We then tried using Redis but faced the this issue. Could this problem(MSSQL Server 2012 for the Hangfire database) be resolved in the new version of ABP?

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    This can solve the problem, and it will be included in the next patch version (8.2.1) https://support.abp.io/QA/Questions/7458/Abp-820-Hangfire-errror-with-redis-db#answer-3a1392c1-9efc-888a-acae-14a9415640ce

  • User Avatar
    0
    cetin.sahin created

    Ok, in this case we will wait for the new version.(8.2.1) Can you refund ticket ? Thanks

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    the ticket was refunded.

Made with ❤️ on ABP v9.1.0-preview. Updated on December 12, 2024, 07:15