Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hangfire BackgroundJob keeps processing and every 30 minutes a new worker is created (PostgreSqlStore) #2433

Open
MrMM1981 opened this issue Aug 21, 2024 · 1 comment

Comments

@MrMM1981
Copy link

MrMM1981 commented Aug 21, 2024

I am running a .NET 8 application with

Hangfire.Core version 1.8.14
Hangfire.AspNetCore version 1.8.14
Hangfire.PostgreSql version 1.20.9

The job is scheduled as expected with background job.enqueue method, it shows up in the dashboard under processing jobs. This job can have a processing duration of multiple hours. What happens is that every 30 minutes a new worker is created and the job is never finished.

I know that the hangfire server keeps running (I see the heartbeat in the logs).

I am using the following configuration for the service.

            var connectionString = configuration.GetValue<string>("Database:ConnectionString");
            var connectionFactory = new NpgsqlConnectionFactory(connectionString, new PostgreSqlStorageOptions()
            {
                PrepareSchemaIfNecessary = true,
                UseSlidingInvisibilityTimeout = true,
                InvisibilityTimeout = TimeSpan.FromHours(12),
                DistributedLockTimeout = TimeSpan.FromHours(12),
            });

            //JobStorage.Current = new PostgreSqlStorage(connectionFactory);

            return services.AddHangfire(config =>
            {
                config.UsePostgreSqlStorage(options => options.UseConnectionFactory(connectionFactory));
            });

Desired situation would be that the job runs to completion (multiple hours of processing needed most of the time).
I'm at a loss.

@MrMM1981
Copy link
Author

Fixed it by using config.UsePostgreSqlStorage(options => options.UseConnectionFactory(connectionFactory), new PostgreSqlStorageOptions()
{
PrepareSchemaIfNecessary = true,
UseSlidingInvisibilityTimeout = true,
InvisibilityTimeout = TimeSpan.FromHours(12),
DistributedLockTimeout = TimeSpan.FromHours(12),
});
});

when using

... return services.AddHangfire(config =>
{
config.UsePostgreSqlStorage(options => options.UseConnectionFactory(connectionFactory));
});
the storage options are not respected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant