Open Closed

[BackgroundJobName("emails")] ignored when using hangfire #689


User avatar
0
BassaSolutions created
  • ABP Framework version: v3.3.1

Documentation https://docs.abp.io/en/abp/latest/Background-Jobs says that the jobsname can be set via an argument: [BackgroundJobName("emails")]

But in Hangfire, the jobname is then still "HangfireJobExecutionAdapter<EmailArgs>.Execute" instead of "emails".

How can the jobname be set?


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

    Hi,

    Add the following code to your module:

    context.Services.AddTransient(serviceProvider =>
    {
        return new DashboardOptions
        {
            DisplayNameFunc = (jobContext, job) =>
            {
                var jobType = serviceProvider.GetRequiredService<IOptions<AbpBackgroundJobOptions>>().Value
                    .GetJob(job.Args.First().GetType());
                return jobType.JobName;
            }
        };
    });
    
  • User Avatar
    0
    BassaSolutions created

    I added it,the defined job name is still not displayed.

    I put it directly after

       // Configure Hangfire
        context.Services.AddHangfire(config =>
        {
            config.UseSqlServerStorage(configuration.GetConnectionString("Default"));
        });
    
  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    Can you share some screenshots?

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    See https://github.com/abpframework/abp/pull/6701

  • User Avatar
    0
    BassaSolutions created

    I found the solution, it had to be added directly into useHangfireDashboard:

      var backgroundJobOptions =
                    context.ServiceProvider.GetRequiredService<IOptions<AbpBackgroundJobOptions>>().Value;
       app.UseHangfireDashboard("/jobs", new DashboardOptions
        {
            DashboardTitle = "MyProject Background Jobs",
            DisplayNameFunc = (jobContext, job) =>
            {
                var jobType = job.Args.First().GetType();
                var abpJobType = backgroundJobOptions.GetJob(jobType);
                return abpJobType.JobName;
            }
        });
    
Made with ❤️ on ABP v9.1.0-preview. Updated on December 13, 2024, 06:09