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

Problem with IReccuringJob implementation #2394

Open
frozzen10 opened this issue Apr 17, 2024 · 0 comments
Open

Problem with IReccuringJob implementation #2394

frozzen10 opened this issue Apr 17, 2024 · 0 comments

Comments

@frozzen10
Copy link

frozzen10 commented Apr 17, 2024

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