scheduleJobsAfter
Allows you to asynchronously execute a scheduled task after a specified interval of time.
Usage/Signature
import { scheduleJobAfter } from '@app/jobs'
await scheduleJobAfter(ctx, scheduleDuration, scheduleMeasure, 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. |
scheduleDuration | number | The waiting period before executing the task. |
scheduleMeasure | Unit of measure for the waiting period | Possible values: milliseconds, seconds, minutes, hours, days, weeks, months, quarters, years |
jobUrl | string | URL of the job created using app.job |
dataObject | object | Object for passing data into the job. |
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 scheduleJobAfter(ctx, 5, 'seconds', jobAction.path(), {
key: '123',
})
})
const jobAction = app.job('jobPath', async (ctx, params) => {
ctx.log('Job called', params)
})