space.schedule.every()
Call a URL on a schedule, with signed calls unless you turn them off.
Creates a job that calls a URL on a schedule, such as @daily or */15 * * * *. Its calls are signed unless you set signed: false, so your endpoint can check them with verify().
function every(
schedule: string,
url: string,
options?: EveryOptions
): Promise<Job>Parameters
schedulestringA 5-field cron schedule, or a shortcut such as
@hourly,@daily,@weekly,@monthly, or@yearly. It cannot be empty. See Schedule format.urlstringThe address to call: an https URL of at most 2,048 characters, without a user name, password, or
#part.options.namestring1 to 100 characters, on one line, unique in the project ignoring case. When you leave it out, the job is named after its schedule and URL, such as
@daily https://shop.example/tasks/reminders, cut to 100 characters.options.descriptionstringAt most 500 characters.
options.timeZonestringAn IANA time zone, such as
Africa/Dar_es_Salaam. UTC when you leave it out. It cannot be empty.options.methodstringGET,POST,PUT,PATCH,DELETE,HEAD, orOPTIONS.POSTwhen you leave it out.options.headersRecord<string, string>At most 50 headers. You cannot set
Host,Content-Length,Transfer-Encoding,Connection,User-Agent, or anyX-Scheduler-header, norAuthorizationwhile calls are signed.options.bodystringAt most 100 KB, and only when
methodisPOST,PUT,PATCH, or left out.options.signedbooleanSign every call with a token your endpoint can check.
truewhen you leave it out. See Verify signed calls.options.audiencestringThe audience the token carries. The URL without its query when you leave it out. A custom audience must use the same scheme and host as the URL.
options.retry.countintegerHow many times to try a failed run again, 0 to 5. 0 when you leave it out, so a failed run is not retried.
options.retry.minBackoffSecondsintegerThe first wait, 1 to 3,600 seconds. 5 when you leave it out.
options.retry.maxBackoffSecondsintegerThe longest wait, 1 to 3,600 seconds, and at least
minBackoffSeconds. 3,600 when you leave it out.options.retry.maxDoublingsintegerHow many times the wait doubles before it grows by the same step, 0 to 16. 5 when you leave it out.
options.retry.maxDurationSecondsintegerStop retrying once the run is this old, 0 to 86,400 seconds. 0, no limit, when you leave it out.
options.attemptDeadlineSecondsintegerHow long to wait for your endpoint to answer, 15 to 1,800 seconds. 180 when you leave it out.
options.signalAbortSignalCancels the call.
options.timeoutMsnumberHow long the call may take, in milliseconds. The
timeoutMsset increateSpacewhen you leave it out, 30,000 by default.
Every rule is checked before the job is sent, so a job the scheduler would refuse fails with validation_failed and nothing is created. How the waits between retries grow is in Retry jobs.
Returns
A promise of the new job.
every() is not sent again after a network failure or a timeout, because the job may already exist. It is sent again, up to retries times, only when it was refused with 429 or 503 before any work began.
Errors
| Code | When |
|---|---|
validation_failed | The schedule, URL, or an option breaks a rule above, or the scheduler cannot read the schedule or time zone. issues names each field |
job_name_taken | Another job in the project has that name, ignoring case. Calling every() twice with the same schedule and URL, and no name, gives this |
job_limit_reached | The project already holds as many jobs as it can |
Every call can also fail with the codes shared by all of space, such as missing_project or network_error. See SpaceError.
Example
import { space } from "digitospace"
const job = await space.schedule.every("0 8 * * MON-FRI", "https://shop.example/tasks/reminders", {
name: "Payment reminders",
timeZone: "Africa/Dar_es_Salaam",
body: JSON.stringify({ channel: "sms" }),
headers: { "Content-Type": "application/json" },
retry: { count: 3, minBackoffSeconds: 30 },
})
console.log(job.id, job.nextRunAt)Last updated