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.namestringRequired

1 to 100 characters, on one line, unique in the project ignoring case.

job.descriptionstring

At most 500 characters.

job.schedulestringRequired

A 5-field cron schedule, or a shortcut such as @daily. It cannot be empty. See Schedule format.

job.timeZonestring

An IANA time zone, such as Africa/Dar_es_Salaam. UTC when you leave it out. It cannot be empty.

job.target.urlstringRequired

An https URL of at most 2,048 characters, without a user name, password, or # part.

job.target.methodstring

GET, POST, PUT, PATCH, DELETE, HEAD, or OPTIONS. POST when 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 any X-Scheduler- header, nor Authorization when signing is on.

job.target.bodystring

At most 100 KB, and only when method is POST, PUT, PATCH, or left out.

job.signing.enabledbooleanRequired

Sign every call. Needed when you give signing. Calls are not signed when you leave signing out, unlike with every().

job.signing.audiencestring

The 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.retryobject

The retry policy: count (0 to 5), minBackoffSeconds (1 to 3,600), maxBackoffSeconds (1 to 3,600, at least minBackoffSeconds), maxDoublings (0 to 16), and maxDurationSeconds (0 to 86,400). Each is a whole number, and one you leave out takes its default. See Retry jobs.

job.attemptDeadlineSecondsinteger

How long to wait for the target to answer, 15 to 1,800 seconds. 180 when you leave it out.

options.signalAbortSignal

Cancels the call.

options.timeoutMsnumber

How long the call may take, in milliseconds. The timeoutMs set in createSpace when 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

CodeWhen
validation_failedA field breaks a rule above, or the scheduler cannot read the schedule or time zone. issues names each field
job_name_takenAnother job in the project has that name, ignoring case
job_limit_reachedThe 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

create-job.ts
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