Organizing scheduled tasks or deferred work in an ASP.NET MVC application

25 views Asked by At

I have a small API application on ASP.NET MVC. One of my endpoints creates an entity and stores it in the database.

Are there any tools that could change this entity after some time (for example, 1 hour)? I.e. I need to perform work automatically on this entity after some time.

I found the library Quartz.NET but it's like it's not really appropriate in this situation. As I understand it, Quartz provides a BackgroundWorker that runs at set intervals.

P.S. I also want to be able to save deferred processes in memory so that after restarting the program all deferred tasks are restored (but I understand that I'm asking too much)

1

There are 1 answers

0
Alexander Burov On

Basically, you need something that will trigger your code. Most of the approaches includes some kind of interval under the hood. Quartz.NET is the post popular solution for this kind of tasks. Also, it includes persistence capabilities, so you don't need to worry about

Also, if you need for example, to mark your entity as expired or something like that. You can leverage fact that no one knows what is in the database, unless they call your API. So you can do that in a "lazy mode" – handle that logic when entity will be requested. Lets say, you have endpoints:

  1. POST /entity to create Entity;
  2. GET /active to list active Entities;

And lets assume you need that Entity to disappear from the /active list after 1 hour. So in the /active handler you can check for the expiration and update accordingly.