Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ and a temporary store for sharing data between prepare and execute functions.
```ts
import { task } from '@commandkit/tasks';

export const reminderTask = task({
export default task({
name: 'reminder',
async execute(ctx) {
// Access custom data passed to the task
Expand Down Expand Up @@ -71,7 +71,7 @@ and execute phases of task execution.
*Example*

```ts
export const conditionalTask = task({
export default task({
name: 'conditional-task',
async prepare(ctx) {
const shouldRun = await checkConditions();
Expand Down
2 changes: 1 addition & 1 deletion apps/website/docs/api-reference/tasks/classes/task.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ and provide a context for accessing CommandKit and Discord.js functionality.
```ts
import { task } from '@commandkit/tasks';

export const cleanupTask = task({
export default task({
name: 'cleanup-old-data',
schedule: { type: 'cron', value: '0 2 * * *' }, // Daily at 2 AM
async prepare(ctx) {
Expand Down
2 changes: 1 addition & 1 deletion apps/website/docs/api-reference/tasks/functions/task.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ logic to conditionally execute based on runtime conditions.
import { task } from '@commandkit/tasks';

// Simple scheduled task
export const dailyBackup = task({
export default task({
name: 'daily-backup',
schedule: { type: 'cron', value: '0 0 * * *' },
async execute(ctx) {
Expand Down
12 changes: 6 additions & 6 deletions apps/website/docs/guide/17-tasks/01-getting-started.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Create a file in `src/app/tasks/` to define your tasks:
```ts
import { task } from '@commandkit/tasks';

export const dailyBackup = task({
export default task({
name: 'daily-backup',
schedule: '0 0 * * *', // Daily at midnight (cron string)
async execute(ctx) {
Expand All @@ -77,7 +77,7 @@ Every task has the following components:
Use cron expressions for recurring tasks:

```ts
export const hourlyTask = task({
export default task({
name: 'hourly-task',
schedule: '0 * * * *', // Every hour
async execute(ctx) {
Expand All @@ -91,7 +91,7 @@ export const hourlyTask = task({
Schedule tasks for specific times:

```ts
export const reminderTask = task({
export default task({
name: 'reminder',
schedule: new Date('2024-01-01T12:00:00Z'), // Specific date
async execute(ctx) {
Expand All @@ -100,7 +100,7 @@ export const reminderTask = task({
});

// Or use timestamps
export const timestampTask = task({
export default task({
name: 'timestamp-task',
schedule: Date.now() + 60000, // 1 minute from now
async execute(ctx) {
Expand All @@ -114,7 +114,7 @@ export const timestampTask = task({
The `execute` function receives a context object with useful properties:

```ts
export const contextExample = task({
export default task({
name: 'context-example',
schedule: '0 */6 * * *', // Every 6 hours
async execute(ctx) {
Expand All @@ -141,7 +141,7 @@ export const contextExample = task({
Use the `prepare` function to conditionally execute tasks:

```ts
export const conditionalTask = task({
export default task({
name: 'conditional-task',
schedule: '0 */2 * * *', // Every 2 hours
async prepare(ctx) {
Expand Down
20 changes: 10 additions & 10 deletions apps/website/docs/guide/17-tasks/04-advanced-patterns.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Organize related tasks to create complex workflows:
// src/app/tasks/data-processing.ts
import { task } from '@commandkit/tasks';

export const dataProcessing = task({
export default task({
name: 'data-processing',
schedule: '0 2 * * *', // Daily at 2 AM
async execute(ctx) {
Expand Down Expand Up @@ -43,7 +43,7 @@ Implement custom retry logic for failed tasks:
// src/app/tasks/retry-example.ts
import { task } from '@commandkit/tasks';

export const retryTask = task({
export default task({
name: 'retry-task',
async execute(ctx) {
const { attempt = 1, maxAttempts = 3 } = ctx.data;
Expand Down Expand Up @@ -87,7 +87,7 @@ Manage tasks that depend on other conditions:
// src/app/tasks/dependency-example.ts
import { task } from '@commandkit/tasks';

export const dependencyTask = task({
export default task({
name: 'dependency-task',
async execute(ctx) {
const { requiredData } = ctx.data;
Expand All @@ -114,7 +114,7 @@ Process multiple items in batches:
// src/app/tasks/batch-processing.ts
import { task } from '@commandkit/tasks';

export const batchProcessor = task({
export default task({
name: 'batch-processor',
schedule: '0 */6 * * *', // Every 6 hours
async execute(ctx) {
Expand Down Expand Up @@ -156,7 +156,7 @@ Track task execution metrics:
// src/app/tasks/metrics.ts
import { task } from '@commandkit/tasks';

export const metricsTask = task({
export default task({
name: 'metrics-task',
schedule: '0 * * * *', // Every hour
async execute(ctx) {
Expand Down Expand Up @@ -197,7 +197,7 @@ Use the context store to manage state across task executions:
// src/app/tasks/state-management.ts
import { task } from '@commandkit/tasks';

export const statefulTask = task({
export default task({
name: 'stateful-task',
schedule: '0 */2 * * *', // Every 2 hours
async prepare(ctx) {
Expand Down Expand Up @@ -235,7 +235,7 @@ Implement cleanup tasks for resource management:
// src/app/tasks/cleanup.ts
import { task } from '@commandkit/tasks';

export const cleanupTask = task({
export default task({
name: 'cleanup',
schedule: '0 3 * * *', // Daily at 3 AM
async execute(ctx) {
Expand Down Expand Up @@ -263,7 +263,7 @@ Implement robust error recovery mechanisms:
// src/app/tasks/error-recovery.ts
import { task } from '@commandkit/tasks';

export const resilientTask = task({
export default task({
name: 'resilient-task',
async execute(ctx) {
const { operation, fallbackOperation } = ctx.data;
Expand Down Expand Up @@ -303,7 +303,7 @@ export const resilientTask = task({
// src/app/tasks/rolling-window.ts
import { task } from '@commandkit/tasks';

export const rollingWindowTask = task({
export default task({
name: 'rolling-window',
schedule: '*/15 * * * *', // Every 15 minutes
async execute(ctx) {
Expand All @@ -325,7 +325,7 @@ export const rollingWindowTask = task({
// src/app/tasks/adaptive-processing.ts
import { task } from '@commandkit/tasks';

export const adaptiveTask = task({
export default task({
name: 'adaptive-task',
schedule: '*/5 * * * *', // Every 5 minutes
async execute(ctx) {
Expand Down
11 changes: 5 additions & 6 deletions packages/tasks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,12 @@ npm install @commandkit/tasks
### 1. Add the plugin to your CommandKit configuration

```ts
import { defineConfig } from 'commandkit/config';
import { tasks } from '@commandkit/tasks';

export default {
plugins: [
tasks(),
],
};
export default defineConfig({
plugins: [tasks()],
});
```

### 2. Set up a driver
Expand All @@ -46,7 +45,7 @@ Create a file in `src/app/tasks/`:
```ts
import { task } from '@commandkit/tasks';

export const refreshExchangeRate = task({
export default task({
name: 'refresh-exchange-rate',
schedule: { type: 'cron', value: '0 0 * * *' }, // daily at midnight
async execute(ctx) {
Expand Down
4 changes: 2 additions & 2 deletions packages/tasks/src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export interface TaskContextData<
* ```ts
* import { task } from '@commandkit/tasks';
*
* export const reminderTask = task({
* export default task({
* name: 'reminder',
* async execute(ctx) {
* // Access custom data passed to the task
Expand All @@ -54,7 +54,7 @@ export class TaskContext<T extends Record<string, any> = Record<string, any>> {
*
* @example
* ```ts
* export const conditionalTask = task({
* export default task({
* name: 'conditional-task',
* async prepare(ctx) {
* const shouldRun = await checkConditions();
Expand Down
4 changes: 2 additions & 2 deletions packages/tasks/src/task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { TaskDefinition, TaskSchedule } from './types';
* ```ts
* import { task } from '@commandkit/tasks';
*
* export const cleanupTask = task({
* export default task({
* name: 'cleanup-old-data',
* schedule: { type: 'cron', value: '0 2 * * *' }, // Daily at 2 AM
* async prepare(ctx) {
Expand Down Expand Up @@ -124,7 +124,7 @@ export class Task<T extends Record<string, any> = Record<string, any>> {
* import { task } from '@commandkit/tasks';
*
* // Simple scheduled task
* export const dailyBackup = task({
* export default task({
* name: 'daily-backup',
* schedule: { type: 'cron', value: '0 0 * * *' },
* async execute(ctx) {
Expand Down