Hangfire | easy way to perform background job processing | Job Scheduling library
kandi X-RAY | Hangfire Summary
kandi X-RAY | Hangfire Summary
Incredibly easy way to perform fire-and-forget, delayed and recurring jobs inside ASP.NET applications. CPU and I/O intensive, long-running and short-running jobs are supported. No Windows Service / Task Scheduler required. Backed by Redis, SQL Server, SQL Azure and MSMQ.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of Hangfire
Hangfire Key Features
Hangfire Examples and Code Snippets
Community Discussions
Trending Discussions on Hangfire
QUESTION
I am debugging this hangfire service job call and can't figure out why hangfire is reporting a completed state while the stored procedures being called are continuing to run for up to ~10 minutes later. The parallel loop is running a stored procedure against up to 200 databases.
The first image below shows the hangfire status (success in ~40 seconds), meaning the job function completed. The second image shows the Stored Procedures issued form the loop still running for many minutes later. As far as I know, hangfire will report success when the job function completes, report timeout after a max wait, or report error is an exception occurs. I don't see how this function could be exiting in 6 seconds if all tasks are awaited.
Hangfire reports success in 40 seconds
Long Running Query Detection shows queries from the job still running and falling in and out of blocking state many minutes later. The commands starting with --===================== represent the SP running against many different databases.
Code I have started debugging ->
...ANSWER
Answered 2022-Apr-07 at 13:46My thoughts are that Parallel.ForEach
does not await for the async lambda so PerformServiceWork
ends before each lambda is still running.
Try to use instead Task.WhenAll
and await on it.
As I recall Parallel.ForEach
is more related to Threading while Tasks
are an abstraction over Threads.
QUESTION
After searching & reading possibly every discussion related to the topic in question, there seemed not to be a clear (or even unclear) solution to this.
I have a job filter that I want to apply to every job. What I want to do is: when the job fails (goes to FailedState
, which happens when the max retry attemps exceed OR it is thrown in that state manually), I want to log a custom, user-friendly exception message to the database (my custom table).
ANSWER
Answered 2022-Apr-04 at 14:00Inject a scoped service provider factory and then create the scoped service provider as needed
QUESTION
I am using Hangfire to schedule jobs in my worker service and want to use the hangfire dashboard. But it seems that there is no way to configure this. All the documentation uses the Startup class but I don't have any startup in my worker service. Also, the OWIN NuGet package is not supported in .Net 5. Here is what I've tried,
...ANSWER
Answered 2022-Mar-16 at 11:32Use the following Program.cs
to configure Hangfire dashboard and your worker service:
QUESTION
Currently we're using Hangfire for scheduling and running long lived tasks. We need these tasks to be able to be retried in the event of an ungraceful shutdown, which Hangfire handles for us.
We're looking to try and move to a producer/consumer model and I've built a basic prototype with Masstransit and AWS SQS, but I have some concerns about how to handle the event of a task being processed during an ungraceful shutdown.
I understand that eventually the SQS visibility timeout will expire and the queued item will be picked up for processing again, but setting that timeout isn't trivial as the length of tasks can be quite varied and I'd prefer if the task could immediately resume/retry processing when the application starts up again.
I got reading about Job Consumers and they seemed to be better fitted to this type of scenario, but all the examples I've seen are using RabbitMQ. Wondering if it's possible/appropriate to do this using SQS, or if there's a better approach?
Thank you for taking the time to read this question :)
...ANSWER
Answered 2022-Mar-09 at 02:22MassTransit will extend the visibility timeout as long as the consumer is still running.
I believe SQS has an upper-limit of something like 12 hours, but you should look it up and find out.
Job Consumers have significantly greater requirements (sagas, temporary queues, etc.) and SQS is really annoying about not having auto-delete/expiring queues, so I'd stick to a regular consumer if you can swing it.
QUESTION
If I have a recurring job that will be run daily inside the .net core application. For that purpose, I'm thinking to use the Hangfire library.
...My question is: will placing this code for executing this daily job here in the Configure method be the most logical place or you would suggest something else?
ANSWER
Answered 2022-Mar-03 at 02:18Asp.net core provide a IHostApplicationLifetime
which provide the methods which could be triggered when the application host has fully started, when the application host has performed a graceful shutdown, when the application host is performing a graceful shutdown.
I think you could put this method inside the IHostApplicationLifetime's ApplicationStarted method will be good.
More details about how to use it, you could refer to this article.
QUESTION
I'm getting this runtime exception with Hangfire after upgrading to .NET6
...ANSWER
Answered 2022-Feb-04 at 09:34As said in the comments, you should look in your Hangfire database for a serialized parameter featuring a ISet
.
It is the deserialization of this parameter which causes the issue, as indicated by :
QUESTION
I am having trouble with Hangfire not disposing the objects it instances within a WebApi on NET 5.
This is my configuration in "ConfigureServices()" (pretty standard, btw):
...ANSWER
Answered 2022-Feb-03 at 17:13As said in the comments, you should use :
QUESTION
I have this piece of code (in synchronous method):
...ANSWER
Answered 2022-Jan-11 at 10:23If it's an asp.net core
application (not just old school asp.net
) there is no problem with task deadlock. SynchronizationContext
(which can cause deadlock without ConfigureAwait(false)
) is null in asp.net core
. There isn’t a SynchronizationContext in ASP.NET Core.
Also without Task.Run
- CallApiAndUpdateSthAsync
will be executed on your current thread until the first await
inside. With Task.Run
- entire CallApiAndUpdateSthAsync
will be executed out of your main execution. You can fix it with adding Task.Yield
in the beginning of CallApiAndUpdateSthAsync
.
QUESTION
I am evaluating Hangfire for an upcoming ASP.net Core project that has several scheduled and reoccurring tasks that need to execute independently of users clicking on web pages. I know that HangFire can do this if the web application is started because a request has come in. I need to know whether or not HangFire can execute a scheduled task between being rebooted and the first web request coming in.
Example: Web server is rebooted at 11pm, and no web requests will come in to cause the web server to spin up until 5am the next morning. A scheduled task needs to be performed at 1AM. Will Hangfire execute this task even though the web application hasn't been started by an incoming request?
If it can, is there a certain setup I need to do to allow this?
Details, if needed: We are going to be using Kestrel hosted in a windows service and sitting behind an NGINX reverse proxy. This setup could be modified if needed to make HangFire meet this requirement.
...ANSWER
Answered 2022-Jan-10 at 11:08When running under IIS it would be a real problem, see Making ASP.NET application always running
But it should not be problem for ASP.NET CORE with kestrel, see
It is not necessary for ASP.NET Core, because application is exposed by a console application that it already always on – there are no timeouts, no suspends and other optimization techniques yet. All you need to do is to use supervisor as written in the official docs for Linux, or use Windows Service with automatic start time, when running on Windows.
QUESTION
I'm trying to setup Hangfire to run a recurring job within Startup.cs
with a standalone method. For this to work, I need to grab some ApplicationServices I have injected already. But the job execution fails with this error:
ANSWER
Answered 2022-Jan-08 at 23:33Here is the implementation that I found best worked for me:
1 Register the service I wanted to schedule in Startup.cs
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install Hangfire
Hangfire is available as a NuGet package. You can install it using the NuGet Package Console window:. After installation, update your existing [OWIN Startup](http://www.asp.net/aspnet/overview/owin-and-katana/owin-startup-class-detection) file with the following lines of code. If you do not have this class in your project or don’t know what is it, please read the [Quick start](http://docs.hangfire.io/en/latest/quick-start.html) guide to learn about how to install Hangfire.
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page