Schedule a Callback

The Scheduler provider allows you to schedule a route on your application to be called in the future after a specified time, or repeatedly on an interval.

Method Signature

startAt(params: startAtParams)

Types

This function takes parameters to configure the scheduled callback:

  • startAt: (String) - The date to start the scheduled callback in ISO format.
  • callback: (String) - The route to be called.
  • id: (Optional String) - Identifier for the scheduled callback, if not provided one will be generated. Use this to cancel a scheduler after created.
  • interval: (Optional IntervalParams) - If specified, the scheduled callback will repeat on this interval.
  • payload: (Optional Object) - Optional data to send to the callback.

IntervalParams:

  • cron: (String) - Use a CRON expression to schedule how often the route is called.
  • until: (UntilParams) - Stop the scheduler after a specified time.

UntilParams:

  • date: (String) - A date in ISO format.
  • maxInvocations: (Int) - The maximum number of times the scheduler should run.

Scheduling a Callback

const session = vcr.createSession();
const scheduler = new Scheduler(session);

await scheduler.startAt({
    id: 'myScheduler',
    startAt: new Date(Date.now() + 5000).toISOString(),
    callback: 'onScheduler',
    payload: {
        text: 'hello world!',
    },
});
session = vcr.createSession()
scheduler = Scheduler(session)

time = datetime.now(timezone.utc) + timedelta(seconds=5000)
startAtParams = StartAtParams()
startAtParams.id = 'myScheduler'
startAtParams.startAt = time.isoformat()
startAtParams.callback = 'parkingReminder'
startAtParams.payload = {
    'text': 'hello world!'
}

await scheduler.startAt(startAtParams)