Hangfire icon indicating copy to clipboard operation
Hangfire copied to clipboard

Problem with IReccuringJob implementation

Open frozzen10 opened this issue 1 year ago • 0 comments

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();
    }
}

frozzen10 avatar Apr 17 '24 13:04 frozzen10