specimen
specimen

Reputation: 1765

Background service in ServiceStack

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?

Upvotes: 2

Views: 402

Answers (2)

Guerrilla
Guerrilla

Reputation: 14866

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

Upvotes: 1

mythz
mythz

Reputation: 143319

I would recommend configuring a Background MQ Service for executing Services in the background.

Upvotes: 2

Related Questions