HyperCronDriver
HyperCronDriver
HyperCron-based task driver for lightweight task scheduling.
This driver uses HyperCron to provide simple, in-memory task scheduling. It's ideal for single-instance applications or development environments where you don't need distributed task scheduling.
Requirements: Requires the hypercron package to be installed.
Example
import { HyperCronDriver } from '@commandkit/tasks/hypercron';
import { setDriver } from '@commandkit/tasks';
const driver = new HyperCronDriver();
setDriver(driver);
Example
// With custom cron service
import { cronService } from 'hypercron';
const customService = cronService.create({
// Custom configuration
});
const driver = new HyperCronDriver(customService);
setDriver(driver);
class HyperCronDriver implements TaskDriver {
constructor(service: = cronService)
create(task: TaskData) => Promise<string>;
delete(identifier: string) => Promise<void>;
setTaskRunner(runner: TaskRunner) => Promise<void>;
}
- Implements:
TaskDriver
constructor
(service: = cronService) => HyperCronDriverCreates a new HyperCron driver instance.
create
(task: TaskData) => Promise<string>Creates a new scheduled task in HyperCron.
This schedules the task using the HyperCron service and starts the service if it's not already running.
delete
(identifier: string) => Promise<void>Deletes a scheduled task from HyperCron.
This cancels the scheduled task and removes it from the cron service.
setTaskRunner
(runner: TaskRunner) => Promise<void>Sets the task execution runner function.
This function will be called by the HyperCron service when a task is due for execution.