I am trying to implement a recurring background job which will clean up my database after several days.
However, I cannot find any start point in ASP.NET Core to push the background job to the queue for the first time. All I found is that I have to make a request and then create a controller to handle that request. This controller is where I create the background job. I think this is a little "manually" and I have to make a request every times I start the app.
Is there anyway to push the background job to the queue instantly when I start the app for the first time?
Startup.cs's Configure method is a perfect place to implement startup logic. Just inject IRecurringJobManager as argument and configure your jobs there:
```c#
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IRecurringJobManager recurringJobs)
{
// ...
// ...
// ...
app.UseMvc();
// configure recurring jobs
recurringJobs.AddOrUpdate("your-job-id", Job.FromExpression
}
```
But what if you want to set cron for reccuring job from config and using reloadOnChange: true? Is there any best practice how to do this?
Decide to use IOptionsMonitor in public void Configure(IApplicationBuilder app, ... - but what if exist better solution?
Most helpful comment
Startup.cs's
Configuremethod is a perfect place to implement startup logic. Just injectIRecurringJobManageras argument and configure your jobs there:```c#
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IRecurringJobManager recurringJobs)
{
// ...
// ...
// ...
app.UseMvc();
// configure recurring jobs(x => x.DoJob(null)), Cron.Weekly());
recurringJobs.AddOrUpdate("your-job-id", Job.FromExpression
}
```