Tasks

Run a task at a precise time, with automatic retries

The Tasks API is an easy way to create, delete and list tasks that will be run at a given date and automatically retried.

⚠️
The Tasks API is currently subject to change, however, any changes we make to the API will not affect your Repeat until it is published again. As such, all of the below methods are available under env.unstable.tasks

Signature

interface Tasks {
  add(
    data: string | JSON,
    options?: {
      id?: string,
      runAt?: string
    }
  ): Promise<{ id: string; }>;
  delete(id: string): Promise<boolean>;
  list(): Promise<{ id: string; }[]>;
}

Methods

  • add(data, options?: { id?, runAt? }) Promise<{ id: string }>
    • The add method allows you to create a new task which the task handler for this Repeat will handle, accepting the following parameters.

      • data: string | JSON
        • The data property accepts a string or JSON object, which will be available to your task handler.

      • options#id?: string
        • The optional id argument allows you to specify your own identifier for this task. If omitted, Repeat will automatically generate an ID for you, which is returned by the method.

      • options#runAt?: string
        • The time that this task should be sent to the task handler. This argument expects an ISO string, such as 2011-10-05T14:48:00.000Z, which is returned by the toISOString() method on a Date object.

  • delete(id)Promise<boolean> The delete method allows you to remove the task associated with a given id. The returned boolean indicates if the delete was successful.
  • list()Promise<{ id: string }[]>
    • The list method returns a list of tasks yet to run for this Repeat.

 

 
 

Last updated on December 6, 2022