Skip to content
Classplugin-tasksv0.1.0-next.1

Task_2

Base class for a task. A field doesn't keep its value between runs since each run gets a fresh instance.

Import it from @seedcord/plugin-tasks/gateway or /http to type this.core as your bot's Core.

abstract class Task_2<
    TData = void,
    TCore extends CoreBase = CoreBase
>
\@RegisterTask()
export class Unban extends Task<{ guildId: string; userId: string }> {
    public async execute(): Promise<void> {
        const { guildId, userId } = this.data;
        await this.core.rest.delete(Routes.guildBan(guildId, userId));
    }
}

Member visibility

Filter class members by access level.

constructor

Constructs a new instance of the Task class

Task_2(context: TaskContext<TData>)

Showing members with Protected visibility and higher.

TData

The payload schedule() passes. A cron job doesn't take a payload.

TData = void

TCore

The Core that this.core has. The transport subpaths set it.

TCore extends CoreBase = CoreBase

core

protected readonly core: TCore

data

The scheduled payload after its trip through the store.

protected readonly data: TaskData<TData>

key

The task's key, from @RegisterTask or the class name.

public readonly key: string

logger

Logs under the task's key, on the channel of the plugin's attach key.

protected readonly logger: Logger

signal

Aborts when the bot shuts down. Pass it to anything slow.

protected readonly signal: AbortSignal

startedAt

protected readonly startedAt: Date

execute()

The task's work. The plugin logs a throw, publishes it as a failed taskRan, and passes it to onError().

public abstract execute(): Promise<void>

onError()

Runs after execute() throws and the plugin has logged the error. If execute() throws after shutdown aborted signal, the plugin skips this.

public async onError?(error: Error): Promise<void>

onOverrun()

Runs in place of execute() when a protected task gets a cron or manual run before its previous run has finished.

public async onOverrun?(): Promise<void>