- ABP Framework version: v8.1.3
- UI Type: Blazor Server
- Database System: PostgreSQL
- Tiered (Auth/Blazor/ApiHost): Yes
- Exception message and full stack trace:
`Started background worker: Volo.Abp.OpenIddict.Tokens.TokenCleanupBackgroundWorker
2024-06-20 17:06:41.303 +02:00 [FTL] HangfireTest.AuthServer terminated unexpectedly!
Volo.Abp.AbpInitializationException: An error occurred during the initialize Volo.Abp.Modularity.OnApplicationInitializationModuleLifecycleContributor phase of the module Volo.Abp.Hangfire.AbpHangfireModule, Volo.Abp.HangFire, Version=8.1.3.0, Culture=neutral, PublicKeyToken=null: An exception was thrown while activating λ:Volo.Abp.Hangfire.AbpHangfireBackgroundJobServer -> λ:Hangfire.JobStorage.. See the inner exception for details.
---> Autofac.Core.DependencyResolutionException: An exception was thrown while activating λ:Volo.Abp.Hangfire.AbpHangfireBackgroundJobServer -> λ:Hangfire.JobStorage.
---> System.InvalidOperationException: Current JobStorage instance has not been initialized yet. You must set it before using Hangfire Client or Server API. For .NET Core applications please call the IServiceCollection.AddHangfire extension method from Hangfire.NetCore or Hangfire.AspNetCore package depending on your application type when configuring the services and ensure service-based APIs are used instead of static ones, like `IBackgroundJobClient` instead of `BackgroundJob` and IRecurringJobManager instead of RecurringJob.
- Steps to reproduce the issue:
- Create a new Blazor Server Project (Tiered, Auth, Blazor, ApiHost) with a postgres Database.
- Following the Documentation "https://docs.abp.io/en/abp/latest/Background-Jobs-Hangfire"
- Install the Package via ABP CLI
- Install Hangfire.PostgreSQL for Storage
- Implement the code i show below
I'm fairly new to background jobs, so I might be missing something. I managed to get the default ABP background jobs running, so I decided to install Hangfire for future scalability as our system grows more complex. However, after many attempts, I couldn't get it to work in our project. To troubleshoot, I decided to try it in a fresh project. Despite following the ABP documentation and searching online for similar issues, I couldn't find a solution to start my project with Hangfire.
These are the packages I installed in the HttpApi.Host project:
- Hangfire.PostgreSql
- Hangfire.Core
This is all the code I added to the HttpApi.Host project:
[DependsOn(
typeof(AbpBackgroundJobsHangfireModule),
typeof(AbpHangfireModule)
)]
public override void ConfigureServices(ServiceConfigurationContext context)
{
var configuration = context.Services.GetConfiguration();
var hostingEnvironment = context.Services.GetHostingEnvironment();
...
ConfigureHangfire(context, configuration);
...
}
private void ConfigureHangfire(ServiceConfigurationContext context, IConfiguration configuration)
{
context.Services.AddHangfire(config =>
{
config.UsePostgreSqlStorage(options =>
{
options.UseNpgsqlConnection(configuration.GetConnectionString("Default"));
});
});
context.Services.AddHangfireServer();
}
public override void OnApplicationInitialization(ApplicationInitializationContext context)
{
...
app.UseAbpHangfireDashboard();
app.UseConfiguredEndpoints();
}
I tried many workarounds, such as adding more Hangfire packages or attempting to initialize JobStorage before the Auth server tries to use it. However, I still don't fully understand the issue.
5 Answer(s)
-
0
hi
Current JobStorage instance has not been initialized yet. You must set it before using Hangfire Client or Server API. For .NET Core applications please call the IServiceCollection.AddHangfire extension method from Hangfire.NetCore or Hangfire.AspNetCore package depending on your application type when configuring the services and ensure service-based APIs are used instead of static ones, like
IBackgroundJobClient
instead ofBackgroundJob
and IRecurringJobManager instead of RecurringJob.- Can you try to remove the
context.Services.AddHangfireServer();
- If 1 is not working, Can you share your
fresh project
by https://wetransfer.com/
liming.ma@volosoft.com
Thanks
- Can you try to remove the
-
0
Hello,
Removing
context.Services.AddHangfireServer();
did not work sadly. I will send you the entire project. -
0
-
0
The program runs now!
Thank you so much. Does this mean that the ABP CLI installs the package in the wrong project?
-
0
You have multiple host projects and only want to use hangfire in API.HOST project. so you shouldn't use the hangfire module in the shared module(domain)