Starts in:
2 DAYS
0 HR
38 MIN
46 SEC
Starts in:
2 D
0 H
38 M
46 S
Open Closed

Hangifre Job manual retry #6504


User avatar
0
rcalv002 created
  • ABP Framework version: v7.2.2
  • UI Type: Blazor Server
  • Database System: EF Core (SQL Server)
  • Tiered (for MVC) or Auth Server Separated (for Angular): no
  • Exception message and full stack trace:
  • Steps to reproduce the issue:

I'm having a problem with jobs that are processed via hangfire module. When a job fails it can be requeued through the hangifre ui, but this interface is more backend than frontend user. I have a page in the application for front end user to see jobs in error state. I want them to be able to click a button and retry this job (not enqueue again, but reprocess failed job just like in backend ui). I've tried many things but in the end I always reach a point where I get stuck.

During job execution can I capture the job id somehow to set it in the error property of my transaction and then use this to retry the job when the user presses the button to retry?


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

    hi

    You can check the source code of https://github.com/abpframework/abp/blob/dev/framework/src/Volo.Abp.BackgroundJobs.HangFire/Volo/Abp/BackgroundJobs/Hangfire/HangfireBackgroundJobManager.cs#L12

    I guess the BackgroundJob API can get the job id.

  • User Avatar
    0
    rcalv002 created

    Hi,

    I had already tried something with BackgroundJob before I posted, I just couldn't get it to work and Is till don't understand how to apply this. In essence a class that processes a type of job

    public class TransactionProcessingJob : AsyncBackgroundJob<TransactionProcessingArgs>, ITransientDependency

    has method

    public override async Task ExecuteAsync(TransactionProcessingArgs args)
    {
        
        try
        {
            IUnitOfWorkManager unitOfWorkManager = _serviceProvider.GetRequiredService<IUnitOfWorkManager>();
            using (unitOfWorkManager.Begin())
            {
                // stuff in here
            }
        }
    
        catch (Exception ex)
        {
            Logger.LogError(ex, "Unable to process transaction {TransactionId}", args.TranId);
            await _emailSender.QueueAsync(
                    to: _config["Notifications:Recipients"],
                    subject: $"Error processing transaction {args.TranId} {args.Channel} {args.ObjectType} {args.ExternalID} for Tenant: {tenantId}",
                    body: $"{ex.Message}</br>{ex.InnerException?.Message}"
                );
    
            using (_currentTenant.Change(tenantId != default ? tenantId : null))
            {
                var transaction = await _transactionRepository.GetAsync(args.TranId);
                transaction.Error = $"{ex.Message}\n{ex?.InnerException?.Message}";
                await _transactionRepository.UpdateAsync(transaction);
            }
    
            throw;
        }
    
    }
    

    In the catch block, it'd be nice to capture job id and set it on a property of the transaction, this way from a dashboard page, using TransactionAppService

    The user can retry that transaction.

    I had already tried to do this adapating an implementation in one of the modules that grabs a distributed lock and IBackgroundJobStore to use FindAsync(guid) to retrieve the job, but since I don't have the job id I can't use IBackgroundJobExecuter to execute the job.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    I think you can use Hangfire API and its job class directly instead of ABP's AsyncBackgroundJob

  • User Avatar
    0
    rcalv002 created

    You mean stop using

    transactionProcessingJob : AsyncBackgroundJob<TArgs> ??

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer
  • User Avatar
    0
    rcalv002 created

    Thanks but I don't think that's an option for me, since all my projects are already using the abp provided implementation, and we don't want to re-implement something the framework is offering, it would be great of the abp implementation could add a property object with information of the particular task so that we can then use BackgroundJob to requeue it..

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    You can replace the Hangfire services. If you have a problem, I can help

    https://github.com/abpframework/abp/tree/dev/framework/src/Volo.Abp.BackgroundJobs.HangFire

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