RecurringCommand, OnSuccess nor OnFailed Called

Hi Team,

We are replacing our use of ServiceStack.Quartz with Background Jobs. We have some long running tasks that are scheduled to run every 15 minutes. The Command can at times run for more than 15 minutes. In the event that a Command runs for 45 minutes, we don’t want multiple Commands to queue up. Is there an already supported way of doing this? What I have tried so far

  1. Have a Command that is executed as a callback after the long running Command that deletes any queued Commands for that same instance from the DB.
  2. Use the OnSuccess and OnFailed callbacks on the BackgroundJobOptions.

No 1. seems to work but I’d prefer if there was an option on the BackgroundJobOptions or a version of RecurringCommand that would do this for me.

No 2. doesn’t work and so I wondering if these callbacks are ever called when the calling RecurringCommand. My code is as follows:

jobs.RecurringCommand<Jobby>(Schedule.Interval(TimeSpan.FromSeconds(1)), options: new BackgroundJobOptions
            {
                Worker = "single",
                OnSuccess = o =>
                {
                    var a = 1;
                },
                OnFailed = o =>
                {
                    var b = 1;
                }
            });

It’s not possible to use Callbacks which are only fired when executing the current command, whereas Recurring commands are persisted rules in the database which fire off new commands. i.e. the code callbacks are not persisted in the database as well.

IMO the easiest solution is just to have the Jobby command set a static boolean to say it’s running and short-circuit and log an warning if another command is still being executed.

1 Like