Starts in:
1 DAY
22 HRS
6 MIN
27 SEC
Starts in:
1 D
22 H
6 M
27 S
Open Closed

Hangfire error when upgrading ABP to v8.2.0 #7433


User avatar
0
thanhlg created

Hi ABP Team,

After upgrading to version 8.2.0, I encountered an error as shown in the image. When using version 8.1.3, Hangfire works fine without that error. Could you please help me check it?


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

    Hi,

    This is because the period is too long.

    You can check this logic https://github.com/abpframework/abp/blob/OrganizationUnitEto/framework/src/Volo.Abp.BackgroundWorkers.Hangfire/Volo/Abp/BackgroundWorkers/Hangfire/HangfireBackgroundWorkerManager.cs#L80-L101

  • User Avatar
    0
    thanhlg created

    In my previous code, I used Cron.Daily(8, 0) because I wanted to perform a task every day at 8 AM. After reviewing the file you sent me, I tried using CronExpression = $"*/50 * * * * *"; but the error still persists. Could you please let me know where I went wrong? And why does it work in version 8.1.3 but not in version 8.2.0?

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    i will check it

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    You can try this, i will fix it in the next patch version.

    [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 >= 1)
            {
                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
    thanhlg created

    Hi liangshiwei,

    The previous error is fixed, but now there's this new error. It only occurs in version 8.2.0, not in version 8.1.3

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    could you create a new ticket, thanks

Made with ❤️ on ABP v9.1.0-preview. Updated on November 20, 2024, 13:06