Ends in:
4 DAYS
10 HRS
29 MIN
56 SEC
Ends in:
4 D
10 H
29 M
56 S
Open Closed

No active server in hangfire background job #6202


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

Hi, I tried to add the hangfire background job to our identity server, but I encountered an issue that no active servers in the hangfire, below is the screenshot:

and here is the background job module:

[DependsOn(
        typeof(AbpBackgroundJobsAbstractionsModule),
        typeof(AbpBackgroundJobsHangfireModule)
    )]
    public class IdentityServerBackgroundJobsModule : AbpModule
    {
        public override void ConfigureServices(ServiceConfigurationContext context)
        {
            var configuration = context.Services.GetConfiguration();

            var connectionString = configuration.GetConnectionString("Default");
            context.Services.AddHangfire(config =>
            {
                config.UseSqlServerStorage(connectionString, new Hangfire.SqlServer.SqlServerStorageOptions()
                {
                    SchemaName = "Hangfire"
                });
            });
        }

        public override void OnApplicationInitialization(ApplicationInitializationContext context)
        {
            var app = context.GetApplicationBuilder();
            var configuration = context.GetConfiguration();

            app.UseHangfireDashboard();

            ConfireHangfireJobs(configuration);
        }

        private void ConfireHangfireJobs(IConfiguration configuration)
        {
            // remove all the jobs if exist
            using (var connection = JobStorage.Current.GetConnection())
            {
                foreach (var recurringJob in StorageConnectionExtensions.GetRecurringJobs(connection))
                {
                    RecurringJob.RemoveIfExists(recurringJob.Id);
                }
            }

            // add new job
            if (Convert.ToBoolean(configuration["RecurringJobs:HousekeepingJob:IsActive"]))
            {
                RecurringJob.AddOrUpdate<HousekeepingJob>(s => s.ExecuteAsync(), configuration["RecurringJobs:HousekeepingJob:CronSchedule"]);
            }
        }
    }

Any help would be greatly appreciated.


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

    hi

    Is there any info in the logs.txt?

  • User Avatar
    0
    nhontran created

    Hi maliming,

    No errors appear in the logs, but I noticed that there is no step for starting Hangfire:

    [22:43:16 INF] Start installing Hangfire SQL objects... [22:43:16 INF] Hangfire SQL objects installed. [22:43:30 INF] Starting IdentityServer4 version 4.1.2+997a6cdd643e46cd5762b710c4ddc43574cbec2e [22:43:32 INF] Using the default authentication scheme Identity.Application for IdentityServer

    Btw, I have shared the source code with you via email, could you please help us check.

    Thank you.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    AddHangfireServer

    context.Services.AddHangfire(config =>
    {
        config.UseSqlServerStorage(connectionString, new Hangfire.SqlServer.SqlServerStorageOptions()
        {
            SchemaName = "Hangfire"
        });
    });
    
    context.Services.AddHangfireServer(options =>
    {
        options.ServerName = "IdentityServerBackgroundJobs";
    });
    

  • User Avatar
    0
    nhontran created

    Hi maliming,

    Thanks for the fix, it is working now.

    But may I know why do we need the AddHangfireServer? it is not included in the documentation: https://docs.abp.io/en/abp/latest/Background-Jobs-Hangfire

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    You should follow Hangfire's document first.

    https://docs.hangfire.io/en/latest/getting-started/aspnet-core-applications.html?highlight=addhangfireserver

  • User Avatar
    0
    nhontran created

    Hi maliming,

    ok, noted on this. Thanks for your support.

Made with ❤️ on ABP v9.1.0-preview. Updated on December 02, 2024, 12:35