HangfireIO / Hangfire

An easy way to perform background job processing in .NET and .NET Core applications. No Windows Service or separate process required
https://www.hangfire.io
Other
9.43k stars 1.71k forks source link

Problem with IReccuringJob implementation #2394

Open frozzen10 opened 7 months ago

frozzen10 commented 7 months ago

I am using Hangfire 1.8.7 in .net 6 app with UseRecurringJob extension and this is how my configuration looks alike:

services.AddHangfire(configuration => configuration
    .UseSQLiteStorage(Configuration["SQLitePath"], new SQLiteStorageOptions())
    .UseRecommendedSerializerSettings()
    .UseRecurringJob("jobs-definition.json"));

services.AddHangfireServer();

I am consuming IRecurringJob interface in a way like below, but problem is that so often my sqllite db file is being corrupted... I think that this is because of Task.Run call, but mine integrators has async method (because of other methods there that are also async) to integrate records... I don't know how to fix it but maybe someone faced issue like mine and can tell me more about what to do.

[AutomaticRetry(Attempts = 0, OnAttemptsExceeded = AttemptsExceededAction.Delete)]
[DisableConcurrentExecution(timeoutInSeconds: 30)]
public class IntegrateAccountsJobHandler : IRecurringJob
{
    private readonly ILogger logger;
    private readonly IConfiguration configuration;
    private readonly IIntegratorFactory integratorFactory;

    public IntegrateAccountsJobHandler(
        ILoggerFactory loggerFactory,
        IConfiguration configuration,
        IIntegratorFactory integratorFactory)
    {
        this.logger = loggerFactory.Create(this);
        this.configuration = configuration;
        this.integratorFactory = integratorFactory;
    }

    public void Execute(PerformContext context)
    {
        Task.Run(() => integratorFactory.Create(typeof(SomeEntity)).Integrate()).GetAwaiter().GetResult();
    }
}