space.schedule.create()
Create a job with every field set yourself.
Creates a job from its full set of fields. every() is the shorter way to call a URL on a schedule; create() takes the job in the same shape the scheduler keeps it.
function create(job: JobInput, options?: CallOptions): Promise<Job>Parameters
job.namestring1 to 100 characters, on one line, unique in the project ignoring case.
job.descriptionstringAt most 500 characters.
job.schedulestringA 5-field cron schedule, or a shortcut such as
@daily. It cannot be empty. See Schedule format.job.timeZonestringAn IANA time zone, such as
Africa/Dar_es_Salaam. UTC when you leave it out. It cannot be empty.job.target.urlstringAn https URL of at most 2,048 characters, without a user name, password, or
#part.job.target.methodstringGET,POST,PUT,PATCH,DELETE,HEAD, orOPTIONS.POSTwhen you leave it out.job.target.headersRecord<string, string>At most 50 headers. You cannot set
Host,Content-Length,Transfer-Encoding,Connection,User-Agent, or anyX-Scheduler-header, norAuthorizationwhen signing is on.job.target.bodystringAt most 100 KB, and only when
methodisPOST,PUT,PATCH, or left out.job.signing.enabledbooleanSign every call. Needed when you give
signing. Calls are not signed when you leavesigningout, unlike withevery().job.signing.audiencestringThe token’s audience. The target URL without its query when you leave it out. A custom audience must use the same scheme and host as the target URL.
job.retryobjectThe retry policy:
count(0 to 5),minBackoffSeconds(1 to 3,600),maxBackoffSeconds(1 to 3,600, at leastminBackoffSeconds),maxDoublings(0 to 16), andmaxDurationSeconds(0 to 86,400). Each is a whole number, and one you leave out takes its default. See Retry jobs.job.attemptDeadlineSecondsintegerHow long to wait for the target 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. A field this page does not list fails with validation_failed.
Returns
A promise of the new job.
create() 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 | A field 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 |
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.create({
name: "Nightly report",
description: "Emails the sales report to the Dar es Salaam branch",
schedule: "0 2 * * *",
timeZone: "Africa/Dar_es_Salaam",
target: {
url: "https://mail.example.com/tasks/report",
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ branch: "dar-es-salaam" }),
},
signing: { enabled: true },
retry: { count: 3, minBackoffSeconds: 10 },
attemptDeadlineSeconds: 300,
})
console.log(job.id, job.signing.effectiveAudience)Last updated