Can Hangfire schedule jobs do this? - asp.net-core

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.

When 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.

Related

Hangfire and main app in different applications

We have web application developed in .NET Core and is hosted on azure. We want to use HangFire for report scheduling.
Our application is multitenant so it will have load of its own, So I want to run these background processes into different server. HangFire has option of Placing Processing into Another Process as Using Console applications or Using Windows Services.
I have gone through HangFire Doc but there is no clear explanation of how this main application (which is .NET CORE) connects to this Console application?
https://docs.hangfire.io/en/latest/background-processing/placing-processing-into-another-process.html
I came across this question but still is not clear to me
How to run Hangfire as a separate process from the main web application?
Your AspNet .Net Core application (the hangfire client) will not communicate directly with the console application (the hangfire server).
Communication is done trhough the storage (the database) : client declares new tasks in the storage, and the server polls the storage (or is notified by the storage depending on the storage technology, like Redis) to execute the tasks.
You need to ensure communication of both client and server with the storage, but not between the client and the server.

IIS Restart Web API in ordered

When IIS Server is the outage, the server is restarted and all applications and web APIs are restarted as well, the problem I'm facing that some Web API depends on BUS. Could we let site/app wait until BUS ready before starting from IIS without touching the application code? In Docker, we can use the WAIT command or other third parties to wait until service is available before starting a container.
The Web API we are built on .Net Core 3.1
Any help is appreciated.
During the startup could you use something like
https://github.com/App-vNext/Polly to enter a period of retry
(https://github.com/App-vNext/Polly#retry). This would allow you to
retry the call to the API until it's hopefully it's available.
Use a windows service to monitor heartbeats of the applications and trigger application pool restarts on applications not working correctly. This should help you get into a running state.
Ultimately I'd try and remove this dependency, if you could give a little more information around the webapi requirements I'd be happy to suggest more ideas.

Web app deployed on kestrel goes into idle mode

I have ASP .Net core webapi deployed on IIS 7.5 (Windows 2008 R2). I have controllers as well as listener classes (which wait for a message to arrive on a RabbitMQ message) which perform the same functionality.
The problem is whenever webapi is deployed on IIS or has some idle time, the RabbitMQ messages don't get picked up. Only if I make a API call to the control does the application 'wake up' and picks up the message.
Tweaks I have tried:
In the application pool,
set 'Idle timeout' to 0 .
set the 'Disable Overlapped Recycled' to true.
set 'Disable recycling for configuration changes'.
I have no idea what is causing this. I need the application to pick up messages immediately and have no idle time. Could anyone please point me in the right direction?
As a complete workaround, you can keep your app alive by sending requests all the time. In my case, I don't even have access to changing IIS settings.
To send requests I use Availability feature in Application Insights -- it lets you create tests that send GET requests to your app as often as every 5 minutes. You can read more about it here.

IIS Application Recycle drops static classes

I'm using Simple Injector in my WCF service. While running it from VS2010 everything is fine. However, when I publish it to my server using IIS 7, after some time (20 min, counted) my WCF loses all registered assemblies, modules, classes in container.
I guess IIS recycles the WCF Service Application Pool and drops my container registrations.
Can anyone help me on this?
While there exists many legitimate cases of using self-hosting WCF services, however, approaching self-hosting just because of IIS recycling may be counter productive.
Hosting in IIS gives you a lot benefit during development and daily operations, and I am not going to repeat what benefits which you could easily find out in google search.
So when IIS receive the first request to your application, it will launch a worker process named "w3wp.exe" according the settings in the application pool associated with your web app. And by default IIS will shutdown in 20 minutes of idle time. Check the Advanced Settings of the application pool, you will find a lot settings for the life cycle. You won't get such flexibility and robustness through self-hosting out of the box.
So basically you could have a few options provided you decide to stay with IIS hosting.
Change the Idle Time-out to 24-hours or even a month.
Write a small program or use cUrl to ping your application every 10 minute.
Leave it as it is
If you want to keep states during operations, save them in disk, then load them during next launch triggered by a request.

WCF App recieving multiple requests per second causing other asp.net apps to stop responding and deadlock

We have a WCF Service using a wsHttpBinding. When it recieves many requests in a short period of time (25 per second for a few minutes) it stops working and our other asp.net applications and pages to stop responding as well. Some of them timeout and eventually we see the following in the event viewer:
ISAPI 'c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll' reported itself as unhealthy for the following reason: 'Deadlock detected'.
Often we get calls about the problem first and restart IIS to solve the problem.
How can we configure our WCF service to handle this many transmissions or at least configure it to not take down our other applications when it can't handle the load. Our classic asp applications run without issues during this time, it's only our .net apps that are effected.
are you running all your asp/wcf sites in the same AppPool? if so, I'd suggest creating a new one and running the WCF service just in that. That in itself might be enough to solve the problem from a practical perspective.
Also can you target a more recent version of the framework with your WCF app? (and leave the other apps the same) It will isolate it much better.