Hangfire fails after a period of time

134 Views Asked by At

I have setup a hangfire service with a server and a dashboard and I've deployed this to IIS , I also created a Db called "HangfireServerDb" and I've started the IIS server. The hangfire server started and created the require schema and tables and also for a period all jobs ran without any issues.

However at some point I can see in the dashboard this on the job that was scheduled for execution.

System.InvalidOperationException: Recurring job can't be scheduled, see inner exception for details. ---> Hangfire.Common.JobLoadException: Could not load the job. See inner exception for the details. ---> System.IO.FileNotFoundException: Could not resolve assembly 'HangfireDashboard.WebApi'.

   at System.TypeNameParser.ResolveAssembly(String asmName, Func`2 assemblyResolver, Boolean throwOnError, StackCrawlMark& stackMark)
   at System.TypeNameParser.ConstructType(Func`2 assemblyResolver, Func`4 typeResolver, Boolean throwOnError, Boolean ignoreCase, StackCrawlMark& stackMark)
   at System.TypeNameParser.GetType(String typeName, Func`2 assemblyResolver, Func`4 typeResolver, Boolean throwOnError, Boolean ignoreCase, StackCrawlMark& stackMark)
   at System.Type.GetType(String typeName, Func`2 assemblyResolver, Func`4 typeResolver, Boolean throwOnError)
   at Hangfire.Common.TypeHelper.DefaultTypeResolver(String typeName)
   at Hangfire.Storage.InvocationData.DeserializeJob()
   --- End of inner exception stack trace ---
   at Hangfire.Storage.InvocationData.DeserializeJob()
   at Hangfire.RecurringJobEntity..ctor(String recurringJobId, IDictionary`2 recurringJob, ITimeZoneResolver timeZoneResolver, DateTime now)
   --- End of inner exception stack trace ---
   at Hangfire.Server.RecurringJobScheduler.ScheduleRecurringJob(BackgroundProcessContext context, IStorageConnection connection, String recurringJobId, RecurringJobEntity recurringJob, DateTime now).

job failing image

I need some help in understanding what am I missing or what might the cause be since like I said it works for a period of time thne I'm getting this.

Registration of httpclient

services.AddHttpClient<WebPlatformHttpClient>(
                httpClient =>
                {
                    httpClient.BaseAddress = new Uri(_configuration["WebPlatform:Api:BaseUri"]);
                    httpClient.DefaultRequestHeaders.Clear();
                    httpClient.DefaultRequestHeaders.Add(HeaderNames.Accept, "application/json");
                });

Httpclient implementation

public class WebPlatformHttpClient
{
    private readonly HttpClient _httpClient;
    private readonly IConfiguration _configuration;

    public WebPlatformHttpClient(HttpClient httpClient, IConfiguration configuration)
    {
        _httpClient = httpClient;
        _configuration = configuration;
    }

    public async Task SendEmailAsync()
    {
        HttpResponseMessage response = await _httpClient.GetAsync(_configuration["WebPlatform:Api:SendEmail"]);

        response.EnsureSuccessStatusCode();
    }
}

Job

 RecurringJob.AddOrUpdate(
            $"Send Email Job",
            "web-platform",
            (WebPlatformHttpClient httpClient) => httpClient.SendEmailAsync(),
            configuration["WebPlatform:Crons:SendEmailCron"], 
            jobOptions);

Further investigations

Application: w3wp.exe CoreCLR Version: 6.0.2623.60508 .NET Version: 6.0.26 Description: The process was terminated due to an unhandled exception. Exception Info: System.AggregateException: One or more hosted services failed to stop. (A task was canceled.) ---> System.Threading.Tasks.TaskCanceledException: A task was canceled. at Hangfire.Processing.TaskExtensions.WaitOneAsync(WaitHandle waitHandle, TimeSpan timeout, CancellationToken token) in C:\projects\hangfire-525\src\Hangfire.Core\Processing\TaskExtensions.cs:line 96 at Hangfire.Processing.BackgroundDispatcher.WaitAsync(TimeSpan timeout, CancellationToken cancellationToken) in C:\projects\hangfire-525\src\Hangfire.Core\Processing\BackgroundDispatcher.cs:line 82 at Hangfire.Server.BackgroundProcessingServer.WaitForShutdownAsync(CancellationToken cancellationToken) in C:\projects\hangfire-525\src\Hangfire.Core\Server\BackgroundProcessingServer.cs:line 148 at Microsoft.Extensions.Hosting.Internal.Host.StopAsync(CancellationToken cancellationToken) --- End of inner exception stack trace --- at Microsoft.Extensions.Hosting.Internal.Host.StopAsync(CancellationToken cancellationToken) at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.WaitForShutdownAsync(IHost host, CancellationToken token) at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token) at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token) at HangfireDashboard.WebApi.Program.Main(String[] args) in D:\CI_Data\TeamCity\buildAgent2\work\ea4fb37391903d0f\Services\HangfireDashboard\Program.cs:line 22 at HangfireDashboard.WebApi.Program.(String[] args)

0

There are 0 best solutions below