Skip to main content

Quik Framework :: Scheduler

Implements a job and task scheduler. Depending on configuration it loads the appropriate executor (optionally database-based) and starts it during application boot.

Installation

npm install @quik/scheduler

Configuration

  • SCHEDULER_EXECUTOR_DATABASE enables the database-backed executor.
  • SCHEDULER_MAX_CONCURRENCY limits concurrent task executions (default: 1).

The scheduler uses app.timezone (default UTC) to evaluate cron expressions.

Usage

Define and register a task:

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

class CleanupTask extends QTask {
constructor() {
super('cleanup', '0 0 * * *');
}

async run() {
// cleanup work
}
}

registerTask(CleanupTask);

API Highlights

  • QTask base class for scheduled tasks.
  • registerTask() registers tasks with the active executor.
  • getTaskScheduler() returns the scheduler instance.
  • QBackgroundRunner executes background tasks.
  • QExecutor.pause(taskName) — pause a running task without stopping the whole scheduler.
  • QExecutor.resume(taskName) — resume a previously paused task.

Pause and resume

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

const scheduler = getTaskScheduler();

// Pause a specific task
scheduler.executor.pause('cleanup');

// Resume it later
scheduler.executor.resume('cleanup');

Scheduling Guarantees

  • Cron schedules run with minute-level resolution.
  • Tasks will not overlap when the concurrency limit is reached. Overlapping runs are skipped and logged as drift.

Testing & Coverage

See the root instructions for details on running pnpm run test:coverage and accessing coverage artifacts.

API Reference

Generated API documentation is available in the scheduler API section.