Background service in ServiceStack

Viewed 143

I've got an application w. AppHost (inside Startup.cs) and also a Configure.Db.cs file. I want to run a background service (Timer based) to routinely do some things, in addition to serving services.

If I add the timer inside Apphost's Configure(), which is run before the Configure.Db, I get into a problem as the background service is dependent on the Db to be configured.

Edit: I just found that it is possible to specify order of Modular startup: https://docs.servicestack.net/modular-startup#modular-startup-prioritization which means I can force the Configure.db to run before Apphost.

Anyway, am I going about this wrong? Should I perhaps have a separate AppHost just for the background job?

2 Answers

You can look at how to do this with hangfire by adding the mix

x mix hangfire-postgres

This will allow you to add services that fire in the background on a cron schedule.

To make it work without a database you need to change the postgres provider to the in-memory provider: https://github.com/perrich/Hangfire.MemoryStorage

Related