Open Closed

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


User avatar
0
yusufsarman 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

Markdown supported.
Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)

7 Answer(s)
  • User Avatar
    0
    liangshiwei created
    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;
        }
    }
    
    
    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    yusufsarman created

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

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    liangshiwei created
    Fullstack Developer

    Add to all projects where hangfire is installed

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    yusufsarman 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?

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    liangshiwei created
    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

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    yusufsarman created

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

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    liangshiwei created
    Fullstack Developer

    the ticket was refunded.

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
Boost Your Development
ABP Live Training
Packages
See Trainings
Mastering ABP Framework Book
The Official Guide
Mastering
ABP Framework
Learn More
Mastering ABP Framework Book
Made with ❤️ on ABP v10.8.0-preview. Updated on September 16, 2026, 14:50
1
ABP Assistant
🔐 You need to be logged in to use the chatbot. Please log in first.