Skip to main content

Recipes

Pause and resume a task

import { getTaskScheduler } from '@quik/scheduler';

const scheduler = getTaskScheduler();

scheduler.pause('cleanup');
scheduler.resume('cleanup');

getTaskScheduler() returns the executor instance itself (the registered IQScheduleExecutor) — pause/resume are defined on the default QExecutor implementation.

Define a task with a structured execution plan

Instead of a cron string, pass an IQExecutionPlan describing the period and time fields:

import { QExecutionPlanPeriod, QTask } from '@quik/scheduler';

class WeeklyReportTask extends QTask {
public constructor() {
super({ period: QExecutionPlanPeriod.WEEKLY, weekdays: new Set([1]), hours: 9, minutes: 0 });
}

public async run() {
// build and send the weekly report
}
}

Reload the scheduler after registering new tasks

import { reloadScheduler } from '@quik/scheduler';

await reloadScheduler();

reloadScheduler() stops and restarts both the IQScheduleExecutor and the IQBackgroundRunner (when present), picking up newly registered tasks without a full application restart.

Limit concurrent executions

Set scheduler.maxConcurrency (env SCHEDULER_MAX_CONCURRENCY) above 1 to allow overlapping runs of the same task; runs beyond the limit are skipped and a drift warning is logged instead of queued.