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
109 changes: 109 additions & 0 deletions apps/website/docs/api-reference/tasks/classes/bull-mqdriver.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
---
title: "BullMQDriver"
isDefaultIndex: false
generated: true
---

import MemberInfo from '@site/src/components/MemberInfo';
import GenerationInfo from '@site/src/components/GenerationInfo';
import MemberDescription from '@site/src/components/MemberDescription';

<!-- This file was generated from the CommandKit source. Do not modify. Instead, re-run the "docgen" script -->


## BullMQDriver

<GenerationInfo sourceFile="packages/tasks/src/drivers/bullmq.ts" sourceLine="38" packageName="@commandkit/tasks" />

BullMQ-based task driver for distributed task scheduling.

This driver uses BullMQ to provide robust, distributed task scheduling with Redis
as the backend. It supports both cron expressions and date-based scheduling, with
built-in retry mechanisms and job persistence.

**Requirements**: Requires the `bullmq` package to be installed.



*Example*

```ts
import { BullMQDriver } from '@commandkit/tasks/bullmq';
import { setDriver } from '@commandkit/tasks';

const driver = new BullMQDriver({
host: 'localhost',
port: 6379,
}, 'my-tasks-queue');

setDriver(driver);
```

*Example*

```ts
// With custom Redis connection options
const driver = new BullMQDriver({
host: 'redis.example.com',
port: 6379,
password: 'your-password',
tls: true,
});
```

```ts title="Signature"
class BullMQDriver implements TaskDriver {
public readonly queue: Queue;
public readonly worker: Worker;
constructor(connection: ConnectionOptions, queueName: string = 'commandkit-tasks')
create(task: TaskData) => Promise<string>;
delete(identifier: string) => Promise<void>;
setTaskRunner(runner: TaskRunner) => Promise<void>;
}
```
* Implements: <code><a href='/docs/next/api-reference/tasks/interfaces/task-driver#taskdriver'>TaskDriver</a></code>



<div className="members-wrapper">

### queue

<MemberInfo kind="property" type={`Queue`} />

The BullMQ queue instance for managing tasks
### worker

<MemberInfo kind="property" type={`Worker`} />

The BullMQ worker instance for processing tasks
### constructor

<MemberInfo kind="method" type={`(connection: ConnectionOptions, queueName: string = 'commandkit-tasks') => BullMQDriver`} />

Creates a new BullMQ driver instance.
### create

<MemberInfo kind="method" type={`(task: <a href='/docs/next/api-reference/tasks/interfaces/task-data#taskdata'>TaskData</a>) => Promise&#60;string&#62;`} />

Creates a new scheduled task in BullMQ.

For cron tasks, this creates a repeating job with the specified cron pattern.
For date tasks, this creates a delayed job that executes at the specified time.
### delete

<MemberInfo kind="method" type={`(identifier: string) => Promise&#60;void&#62;`} />

Deletes a scheduled task from BullMQ.

This removes the job and all its children (for repeating jobs) from the queue.
### setTaskRunner

<MemberInfo kind="method" type={`(runner: <a href='/docs/next/api-reference/tasks/types/task-runner#taskrunner'>TaskRunner</a>) => Promise&#60;void&#62;`} />

Sets the task execution runner function.

This function will be called by the BullMQ worker when a job is due for execution.


</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
---
title: "HyperCronDriver"
isDefaultIndex: false
generated: true
---

import MemberInfo from '@site/src/components/MemberInfo';
import GenerationInfo from '@site/src/components/GenerationInfo';
import MemberDescription from '@site/src/components/MemberDescription';

<!-- This file was generated from the CommandKit source. Do not modify. Instead, re-run the "docgen" script -->


## HyperCronDriver

<GenerationInfo sourceFile="packages/tasks/src/drivers/hypercron.ts" sourceLine="36" packageName="@commandkit/tasks" />

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*

```ts
import { HyperCronDriver } from '@commandkit/tasks/hypercron';
import { setDriver } from '@commandkit/tasks';

const driver = new HyperCronDriver();
setDriver(driver);
```

*Example*

```ts
// With custom cron service
import { cronService } from 'hypercron';

const customService = cronService.create({
// Custom configuration
});

const driver = new HyperCronDriver(customService);
setDriver(driver);
```

```ts title="Signature"
class HyperCronDriver implements TaskDriver {
constructor(service: = cronService)
create(task: TaskData) => Promise<string>;
delete(identifier: string) => Promise<void>;
setTaskRunner(runner: TaskRunner) => Promise<void>;
}
```
* Implements: <code><a href='/docs/next/api-reference/tasks/interfaces/task-driver#taskdriver'>TaskDriver</a></code>



<div className="members-wrapper">

### constructor

<MemberInfo kind="method" type={`(service: = cronService) => HyperCronDriver`} />

Creates a new HyperCron driver instance.
### create

<MemberInfo kind="method" type={`(task: <a href='/docs/next/api-reference/tasks/interfaces/task-data#taskdata'>TaskData</a>) => Promise&#60;string&#62;`} />

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

<MemberInfo kind="method" type={`(identifier: string) => Promise&#60;void&#62;`} />

Deletes a scheduled task from HyperCron.

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

<MemberInfo kind="method" type={`(runner: <a href='/docs/next/api-reference/tasks/types/task-runner#taskrunner'>TaskRunner</a>) => Promise&#60;void&#62;`} />

Sets the task execution runner function.

This function will be called by the HyperCron service when a task is due for execution.


</div>
16 changes: 16 additions & 0 deletions apps/website/docs/api-reference/tasks/classes/index.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
title: "Classes"
isDefaultIndex: true
generated: true
---

import MemberInfo from '@site/src/components/MemberInfo';
import GenerationInfo from '@site/src/components/GenerationInfo';
import MemberDescription from '@site/src/components/MemberDescription';

<!-- This file was generated from the CommandKit source. Do not modify. Instead, re-run the "docgen" script -->


import DocCardList from '@theme/DocCardList';

<DocCardList />
119 changes: 119 additions & 0 deletions apps/website/docs/api-reference/tasks/classes/task-context.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
---
title: "TaskContext"
isDefaultIndex: false
generated: true
---

import MemberInfo from '@site/src/components/MemberInfo';
import GenerationInfo from '@site/src/components/GenerationInfo';
import MemberDescription from '@site/src/components/MemberDescription';

<!-- This file was generated from the CommandKit source. Do not modify. Instead, re-run the "docgen" script -->


## TaskContext

<GenerationInfo sourceFile="packages/tasks/src/context.ts" sourceLine="48" packageName="@commandkit/tasks" />

Execution context provided to task functions.

This class provides access to the task instance, custom data, CommandKit instance,
and a temporary store for sharing data between prepare and execute functions.



*Example*

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

export const reminderTask = task({
name: 'reminder',
async execute(ctx) {
// Access custom data passed to the task
const { userId, message } = ctx.data;

// Access CommandKit and Discord.js client
const user = await ctx.commandkit.client.users.fetch(userId);
await user.send(`Reminder: ${message}`);

// Use the store to share data between prepare and execute
const processedCount = ctx.store.get('processedCount') || 0;
ctx.store.set('processedCount', processedCount + 1);
},
});
```

```ts title="Signature"
class TaskContext<T extends Record<string, any> = Record<string, any>> {
public readonly store = new Map<string, any>();
constructor(_data: TaskContextData<T>)
task: Task
client: Client
data: T
commandkit: CommandKit
}
```

<div className="members-wrapper">

### store

<MemberInfo kind="property" type={``} />

Temporary key-value store for sharing data between prepare and execute functions.

This store is useful for passing computed values or state between the prepare
and execute phases of task execution.



*Example*

```ts
export const conditionalTask = task({
name: 'conditional-task',
async prepare(ctx) {
const shouldRun = await checkConditions();
ctx.store.set('shouldRun', shouldRun);
return shouldRun;
},
async execute(ctx) {
const shouldRun = ctx.store.get('shouldRun');
if (shouldRun) {
await performAction();
}
},
});
```
### constructor

<MemberInfo kind="method" type={`(_data: <a href='/docs/next/api-reference/tasks/interfaces/task-context-data#taskcontextdata'>TaskContextData</a>&#60;T&#62;) => TaskContext`} />

Creates a new task execution context.
### task

<MemberInfo kind="property" type={`<a href='/docs/next/api-reference/tasks/classes/task#task'>Task</a>`} />

Gets the task instance being executed.
### client

<MemberInfo kind="property" type={`Client`} />

Gets the Discord.js client.
### data

<MemberInfo kind="property" type={`T`} />

Gets the custom data passed to the task execution.
### commandkit

<MemberInfo kind="property" type={`<a href='/docs/next/api-reference/commandkit/classes/command-kit#commandkit'>CommandKit</a>`} />

Gets the CommandKit instance for accessing bot functionality.

This provides access to the Discord.js client, CommandKit store, and other
bot-related functionality.


</div>
Loading