ChatiumFor developersPlaygroundPricing
Sign in

scheduleJobAt

Allows you to asynchronously execute a scheduled task at a specific time.

Usage/Signature

import { scheduleJobAt } from '@app/jobs'
scheduleJobAt(ctx, startAt, jobUrl, dataObject)

Arguments

Parameter Type Description
ctx app.Ctx Request context. Used for internal implementation, storing information about the user who created the record, and allows executing the request in the appropriate transaction.
startAt Date A Date object indicating when to execute the task.
jobUrl string A link to the task created using app.job.
dataObject object An object for passing data into the task.

Returns

string - The task ID, which can be used to cancel it with the cancelJob function.

Example of Function Usage

import { scheduleJobAt } from '@app/jobs'

app.screen('/', function (ctx, req) {
  return (
    <screen>
      <button onClick={setJobAction.apiCall()} class={['primary', 'section']}>
        Schedule job
      </button>
    </screen>
  )
})

const setJobAction = app.apiCall('scheduleJob', async (ctx, req) => {
  const date = new Date("2025-01-26");
  await scheduleJobAt(ctx, date, jobAction.path(), {
    key: '123',
  })
})

const jobAction = app.job('jobPath', async (ctx, params) => {
  ctx.log('Job called', params)
})