Skip to main content
Version: Next

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);
Signature
class HyperCronDriver implements TaskDriver {
constructor(service: = cronService)
create(task: TaskData) => Promise<string>;
delete(identifier: string) => Promise<void>;
setTaskRunner(runner: TaskRunner) => Promise<void>;
}

constructor

method
(service: = cronService) => HyperCronDriver

Creates a new HyperCron driver instance.

create

method
(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

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

Deletes a scheduled task from HyperCron.

This cancels the scheduled task and removes it from the cron service.

setTaskRunner

method
(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.