Skip to main content
Version: 1.x

TaskDriverManager

TaskDriverManager​

Manages the active task driver and provides a unified interface for task operations.

This class acts as a facade for the underlying task driver, providing methods to create, delete, and manage tasks. It ensures that a driver is set before any operations are performed.

Example

import { TaskDriverManager } from '@commandkit/tasks';

const manager = new TaskDriverManager();
// Set your preferred driver here

// Now you can create and manage tasks
const taskId = await manager.createTask({
name: 'my-task',
data: { userId: '123' },
schedule: { type: 'date', value: Date.now() + 60000 },
});
Signature
class TaskDriverManager {
public driver: TaskDriver | null = null;
setDriver(driver: TaskDriver) => void;
createTask(task: TaskData) => Promise<string>;
deleteTask(identifier: string) => Promise<void>;
setTaskRunner(runner: TaskRunner) => Promise<void>;
}

driver​

property
TaskDriver | null

setDriver​

method
(driver: TaskDriver) => void

Sets the active task driver.

This method must be called before any task operations can be performed. The driver handles all scheduling, persistence, and execution timing.

createTask​

method
(task: TaskData) => Promise<string>

Creates a new scheduled task.

This method delegates to the active driver to schedule the task according to its configuration. The task will be executed when its schedule is due.

deleteTask​

method
(identifier: string) => Promise<void>

Deletes a scheduled task by its identifier.

This method delegates to the active driver to remove the task from the scheduling system and cancel any pending executions.

setTaskRunner​

method
(runner: TaskRunner) => Promise<void>

Sets the task execution runner function.

This method delegates to the active driver to set up the execution handler that will be called when tasks are due to run.