Open Closed

ABP Background Job retry #2042


User avatar
0
BassaSolutions created
  • ABP Framework version: v4.3.3

How is it possible to change the retry count of specific jobs?

With hangfire, this attribute can be used: [AutomaticRetry(Attempts = 0)]. But it doesnt seem to work with ABP. We need different retry attempt counts for each job.


1 Answer(s)
  • User Avatar
    0
    enisn created
    Support Team .NET Developer

    Documentation of Background Jobs says:

    "Background jobs are persistent that means they will be re-tried and executed later even if your application crashes."

    ...

    • Retries job execution until the job successfully runs or timeouts. Default timeout is 2 days for a job. Logs all exceptions.
    • Increasingly waits between retries for a job. It waits 1 minute for the first retry, 2 minutes for the second retry, 4 minutes for the third retry and so on.

    Background Jobs are designed to execute that job if whatever happens.

    Short answer is No. You can't set different retry count for each job with DefaultBackgroundJobManager. If you want a custom implementation, you can replace DefaultBackgroundJobManager with your CustomBackgroundJobManager. So it's open-source: https://github.com/abpframework/abp/blob/dev/framework/src/Volo.Abp.BackgroundJobs/Volo/Abp/BackgroundJobs/DefaultBackgroundJobManager.cs


    You can create your own background service like that:

    [Dependency(ReplaceServices = true)]
    public class CustomBackgroundJobManager : DefaultBackgroundJobManager
    {
        public CustomBackgroundJobManager(IClock clock, IBackgroundJobSerializer serializer, IBackgroundJobStore store, IGuidGenerator guidGenerator) : base(clock, serializer, store, guidGenerator)
        {
        }
    
        protected override Task<Guid> EnqueueAsync(string jobName, object args, BackgroundJobPriority priority = BackgroundJobPriority.Normal, TimeSpan? delay = null)
        {
            // Custom implementation
            throw new NotImplementedException();
        }
    }
    
Made with ❤️ on ABP v9.1.0-preview. Updated on November 11, 2024, 11:11