Hangfire server stopped
I’m using .Net Core 2.0 with Hangfire 1.7.0-beta BackgroundJob.Enqueue to call in background process my function that will save the data to database and also RecurringJob.AddOrUpdate to call my function that will send bulk email. But suddenly the process stops. And when I check the logs on the server, it says “Hangfire Server stopped.” Please help me. Thanks in advance.
See also questions close to this topic
-
Should I use async/await in Hangfire job ?
I recently started using Hangfire to handle my background jobs in an ASP.NET project.
My jobs are involving lots, lots (and lots) of HTTP calls using
WebRequest
(I may migrate to something else, but that's for later).While browsing SO on this subject, I stumbled upon people who do async calls in hangfire.
Is there any point in using
async/await
tasks inside a Hangfire job ? I'm aware that it is a queue, so jobs won't execute concurrently, but since my project has no GUI, is there any reason I would useasync/await
to do my HTTP calls inside a Hangfire job ?PS : The requests that are involving a long-running job use the Task "design pattern", so clients won't experience any timeout
-
Hangfire and nlog
I'm using hangfire and nlog together and wondering if this is possible...
When an unhandled exception occurs, all that appears in the log files are messages similar to this:
2018-04-23 11:04:34.4393 ERROR Failed to process the job '1047': an exception occurred.
Is it possible to get hangfire to log the exception that was thrown so that I can filter them via nlog? Its generating a lot of noise via email which is not what I want going forward. The hangfire docs don't suggest a way to do this
-
.NET core: Hangfire setup with NLog
I have an .NET Core 2 powered API that I would like to add Hangfire to. The project is already using NLog to log to a MySQL database and it works fine, but when I try to setup and use Hangfire I get the following error:
Method not found: 'Hangfire.Logging.ILog Hangfire.Logging.LogProvider.GetCurrentClassLogger()'.
The Hangfire dashboard works, but I get that error when trying to enqueue my first job like this:
BackgroundJob.Enqueue(() => Console.WriteLine("Fire-and-forget"));
I have read the Hangfire documentation over at: http://docs.hangfire.io/en/latest/configuration/configuring-logging.html
and it says:
Starting from Hangfire 1.3.0, you are not required to do anything, if your application already uses one of the following libraries through the reflection (so that Hangfire itself does not depend on any of them). Logging implementation is automatically chosen by checking for the presence of corresponding types in the order shown below.
That list includes NLog, so apparently I am doing something wrong.
In my
csproj
I have:<PackageReference Include="Hangfire" Version="1.6.19" /> <PackageReference Include="Hangfire.MySqlStorage" Version="1.0.5" /> <PackageReference Include="MySql.Data" Version="8.0.11" /> <PackageReference Include="NLog" Version="4.5.3" /> <PackageReference Include="NLog.Web.AspNetCore" Version="4.5.2" />
In
Startup.cs
andConfigureServices
I have:services.AddHangfire(config => config.UseStorage(new MySqlStorage(appSettings.GetConnectionString("HangfireConnectionString"))));
and in
Configure
I have:loggerFactory.AddNLog(); env.ConfigureNLog("nlog.config"); app.UseHangfireDashboard(); app.UseHangfireServer();
My
nlog.config
contains:<target name="database" xsi:type="Database" dbProvider="MySql.Data.MySqlClient.MySqlConnection, MySql.Data" connectionString="server=localhost;Database=nlog;user id=root;password=;SslMode=none;">
and it does log to the MySQL database without Hangfire, so that seems to be working.
Looking at the Nlog documentation at:
https://github.com/NLog/NLog.Web/wiki/Getting-started-with-ASP.NET-Core-2
They seem to add NLog in
Program.cs
instead ofStartup.cs
, so I tried that approach as well, but I still get the same error.