Skip to main content

Schedule

The $schedule module lets you create, get, update, pause, resume, and delete scheduled jobs.

Schedule types: ONE_TIME (run once at a time), CRON (cron expression), RECURRING (fixed interval).


Import / Usage

const { AppnestFunctions } = require('appnest-app-sdk-utils');
const { $schedule } = AppnestFunctions;
// or from path:
// const AppnestFunctions = require('<path-to-sdk>/appnestFunctions');
// const { $schedule } = AppnestFunctions;

Common Fields

FieldTypeRequiredConstraints
namestringyesNon-empty, max 30 characters.
typestringyesONE_TIME | CRON | RECURRING
dataobjectyes (create/update)At least one key; payload delivered to the scheduled handler.

Type-specific (create / update)

ONE_TIME

FieldTypeRequiredDescription
runAtstringyesDate-time string (e.g. ISO 8601: YYYY-MM-DDTHH:mm:ssZ).

Do not pass cronExpression or repeat for ONE_TIME.

CRON

FieldTypeRequiredDescription
cronExpressionstringyesValid cron expression (e.g. 0 * * * * for hourly).

Do not pass runAt or repeat for CRON.

RECURRING

FieldTypeRequiredDescription
repeatobjectyes{ frequency: number, timeUnit: string }
repeat fieldTypeRequiredConstraints
frequencynumberyesInteger >= 1; if timeUnit is MINUTES, >= 10.
timeUnitstringyesMINUTES | HOURS | DAYS | WEEKS | MONTHS | YEARS

Do not pass runAt or cronExpression for RECURRING.


API

MethodSignatureDescription
create$schedule.create({ name, type, data, runAt | cronExpression | repeat })Create a schedule. Returns nothing.
get$schedule.get({ name, type })Get schedule by name and type. Returns nothing.
update$schedule.update({ name, type, data, runAt | cronExpression | repeat })Update existing schedule. Returns nothing.
pause$schedule.pause({ name, type })Pause a schedule. Returns nothing.
resume$schedule.resume({ name, type })Resume a paused schedule. Returns nothing.
delete$schedule.delete({ name, type })Delete a schedule. Returns nothing.

Return: All schedule methods return Promise<void> (no response body). They resolve when the operation completes.


Examples

ONE_TIME:

await $schedule.create({
name: 'dailyReportOnce',
type: 'ONE_TIME',
runAt: '2026-02-05T10:00:00Z',
data: { reportType: 'daily' }
});

CRON:

await $schedule.create({
name: 'hourlyReport',
type: 'CRON',
cronExpression: '0 * * * *',
data: { reportType: 'hourly' }
});

RECURRING:

await $schedule.create({
name: 'everyTwoHours',
type: 'RECURRING',
repeat: { frequency: 2, timeUnit: 'HOURS' },
data: { task: 'sync' }
});

Get: (returns nothing; use to ensure the schedule exists or to trigger a side effect)

await $schedule.get({ name: 'hourlyReport', type: 'CRON' });

Update:

await $schedule.update({
name: 'hourlyReport',
type: 'CRON',
cronExpression: '0 */2 * * *',
data: { reportType: 'hourly' }
});

Pause / Resume:

await $schedule.pause({ name: 'hourlyReport', type: 'CRON' });
await $schedule.resume({ name: 'hourlyReport', type: 'CRON' });

Delete:

await $schedule.delete({ name: 'hourlyReport', type: 'CRON' });