I am working on an asp.net mvc-5 web application, deployed under windows 2012 & iis-8. my asp.net mvc have many CRUD operations which are implemented as action methods inside my asp.net mvc. But my asp.net mvc web application will be doing scheduled long running network scan process, the network scan will mainly do the following steps:-
- Get the list of our servers and vms from our database.
- Get the scanning username and password for each server and vm from a third party tool, using Rest API.
- Call some powershell scripts to retrieve the servers & vms info such as network info, memory, name, etc.
- Update our ERP system with the scan info using Rest API.
Now I did a pilot project using the following approach:-
- I define a Model method inside my asp.net mvc to do the above 4 steps.
- Then I install hangfire tool which will be calling the scan method on predefined scheduler.
- Also I create a View inside my asp.net mvc which allow users to set the hangfire schedule settings (this require to do an IIS reset on the host server for hangfire to get the new settings).
Now I run a test scan for a round 150 servers which took around 40 minutes to complete , and it worked well. The only thing I noted is that if I set the schedule to run on non-business hours (where no activity is made on IIS) then hangfire will not be able to call the job, and once the first request is made the missed jobs will run. I overcome this limitation by defining a windows task which calls IIS each 15 minutes, to keep application pool live, and it worked well...
Now the other approach I am reading about is doing my above is as follow:-
- Instead of defining Model method inside asp.net mvc to do the scan, I can create a separate console application to do the scan.
- Then inside my asp.net mvc to create a view which allow users to create and schdule a task inside the windows tasks scheduler. I can do so by integrating with the windows task scheduler API.
- Where this windows task will be calling the console application.
Now I am not sure which approach is better and why ? now generally speaking long running/background jobs should not run under iis.. But at the same time defining these long running processes as console app and calling these apps inside windows task scheduler will create extra dependencies on my web application. And will add extra effort when moving the application from move server to another (for example from test to live).. Beside this I read that tools such as hangfire, quartz and other are designed to allow running long running tasks inside IIS and they eliminate the need to create console applications and scheduling these console applications using task scheduler .. So can anyone advice on this?