Closed murh-lego closed 6 months ago
Ok it seems that migration couldn't be applied. Retries were invoked resulting in final message:
(Hangfire.SqlServer.SqlServerObjectsInstaller) Was unable to perform the Hangfire schema migration due to an exception. Ignore this message unless you've just installed or upgraded Hangfire.
Can I somehow manually invoke migration or perhaps increase the retries?
Ended up writing my own runner which tries to perform installation and adding the jobs
IScheduledJobsStartupBootstrapper just bundels all those AddOrUpdate calls in one spot in some other assembly
public sealed class ScheduledJobsStartupRunner(
IScheduledJobsStartupBootstrapper bootstrapper,
SqlServerConnectionString connectionString,
ILogger<ScheduledJobsStartupRunner> logger
) : BackgroundService
{
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
while (!stoppingToken.IsCancellationRequested)
{
try
{
SqlServerObjectsInstaller.Install(new SqlConnection(connectionString));
bootstrapper.AddScheduledJobs();
logger.LogInformation("Startup scheduled jobs added successfully!");
break;
}
catch (Exception e)
{
logger.LogDebug(e, "Something went wrong bootstrapping scheduled jobs");
logger.LogWarning("Could not bootstrap scheduled jobs, retrying");
await Task.WhenAny(Task.Delay(TimeSpan.FromSeconds(5), stoppingToken));
}
}
}
}
Ok it seems that migration couldn't be applied. Retries were invoked resulting in final message:
Hm, do you have any ideas what was the exception? It should be logged if logging template includes exceptions.
Ok it seems that migration couldn't be applied. Retries were invoked resulting in final message:
Hm, do you have any ideas what was the exception? It should be logged if logging template includes exceptions.
Yes, database wasn't available for some time and retries reached threshold. Eventually the db was up, but the service couldn't recover from it.
I've added resilient initializer to migrate db and add jobs that start from application startup life
Hi, has anyone encountered similar?
I'm unable to prepare a schema on service startup. I'm running .NET Aspire with SQL Server, simple mssql hosted in docker container.
Local db is working a-ok.
Aspire will run clean-slate on each startup. Meaning some time will pass until SQL container is up and running. However, when he is and when my migrations run through.
The service I have hangfire on keeps throwing the below logs.
This is my connection string:
This is my setup:
This is the log: