ChatiumFor developersPlaygroundPricing
Sign in

scheduleJobAsap

Allows you to asynchronously execute a scheduled task as soon as possible.

Usage/Signature

import { scheduleJobAsap } from '@app/jobs'
scheduleJobAsap(ctx, 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.
jobUrl string Link to the task created using app.job
dataObject object Object for passing data into the task.

Returns

string - The id of the task, which can be canceled using the cancelJob function.

Example of Function Usage

import { scheduleJobAfter } 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) => {
  await scheduleJobAsap(ctx, jobAction.path(), {
    key: '123',
  })
})

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