Note from the author: This is probably blasphemy to many and doesn't scale very well, but when can work very well for small business scenarios. I usually keep all of my automatically run processes in the API's AutomationController.cs
file. Then I expose them via this page. This allows me to quickly debug production issues, by bringing down the most recent production database backup from production into a development environment, set a breakpoint and manually invoke via this page. This page also allows us to manually invoke system automation processes on demand.
Always make sure that automation endpoints don't cross workloads for subsequent runs. For example, if there is a process that runs daily that sends an email out to users with expiring payment information, running that process again shouldn't send duplicate notifications to users.
Business Logic for Automation is in the API's "Code" project's automation folder. e.g.
/YourCompanyApi.Code/Automation/
. A base class TaskRunnerBase.cs
file exists in that directory, which is meant to help with the creation of automation endpoints. The business logic for these endpoints are encapsulated in a try / catch block and logs are sent to a designated recipient configured in the appsettings.json config file of the API.
Schedule the invocation of the automation endpoints using Windows Task Scheduler.
For more scalable job runners, check out Hangfire.