Scheduled timer to run in background

We have a need to add a scheduled timer to our ServiceStack services. We would like to run one or more activities every x seconds.

Before we develop it I thought I’d check…
Does ServiceStack already have this functionality built-in in any form?

1 Like

We don’t provide any specific functionality to help manage timers, for times where we need to run a background task we use a Long Running task in Background MQ or manage our own Background Thread in Redis Pub/Sub Server.

But when we need tasks run every interval, we prefer to use a OS Scheduled task like a cronjob or 3rd Party monitoring service like https://uptimerobot.com or https://www.pingdom.com

Depending on the use-case though, you may want to use a MQ Worker Service Template which uses .NET’s Worker Service that effectively runs a managed task indefinitely for a specified amount of time, e.g:

1 Like

Thanks for the info @mythz

Some details about the use-case…

When a service requests actions certain CRUD changes in the db we currently use RabbitMQ to synchronise these changes out to a search index. Data integrity is important so we need a fallback mechanism for when rabbit is unavailable. So we decided to update a column in the database indicating that a document needs re-indexing on the search index.

The scheduled, frequent task is to poll for these db index requests and action them.

I like using a scheduled task/3rd party ping services hitting a HTTP endpoint for this so no background thread/timer needs managing in the Web App & can call same HTTP endpoint to invoke normally.

1 Like

ok, makes sense; I like the simplicity - it helps our customers implement these background tasks themselves.

1 Like