Skip to main content
Version: Next

Task

task

Creates a new task definition.

This is the main function for defining tasks in your application. Tasks can be scheduled using cron expressions or specific dates, and can include preparation logic to conditionally execute based on runtime conditions.

Example

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

// Simple scheduled task
export const dailyBackup = task({
name: 'daily-backup',
schedule: { type: 'cron', value: '0 0 * * *' },
async execute(ctx) {
await performBackup();
},
});
Signature
function task<T extends Record<string, any> = Record<string, any>>(data: TaskDefinition<T>): Task<T>

Parameters

data

parameter