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.
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 }>
- data: string | JSON
- options#id?: string
- options#runAt?: string
The add
method allows you to create a new task which the task
handler for this Repeat will handle, accepting the following parameters.
The data
property accepts a string or JSON object, which will be available to your task
handler.
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.
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>
Thedelete
method allows you to remove the task associated with a givenid
. The returnedboolean
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