Skip to content

Commit bce075d

Browse files
committed
Make task args optional
1 parent 9705a6e commit bce075d

File tree

4 files changed

+9
-9
lines changed

4 files changed

+9
-9
lines changed

src/childWorker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ export class WakaQChildWorker {
115115
}
116116
}
117117

118-
private async _executeTask(task: Task, variables: unknown, queue?: WakaQueue) {
118+
private async _executeTask(task: Task, variables?: unknown, queue?: WakaQueue) {
119119
this._sendPingToParent(task.name, queue?.name);
120120
this.logger.debug(`running with args ${variables}`);
121121
if (this.wakaq.beforeTaskStartedCallback) await this.wakaq.beforeTaskStartedCallback(task);

src/task.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export class Task<TData = unknown> {
1414

1515
constructor(
1616
wakaq: WakaQ,
17-
fn: (variables: TData) => Promise<void>,
17+
fn: (variables?: TData) => Promise<void>,
1818
name?: string,
1919
queue?: WakaQueue | string,
2020
softTimeout?: Duration,
@@ -42,16 +42,16 @@ export class Task<TData = unknown> {
4242
/*
4343
Run task in the background.
4444
*/
45-
public async enqueue(variables: TData) {
45+
public async enqueue(variables?: TData) {
4646
return await this.wakaq.enqueueAtEnd(this.name, variables, this.queue);
4747
}
4848

4949
/*
5050
Run task in the background after eta.
5151
*/
52-
public async enqueueAfterDelay(eta: Duration | Date | number, ...args: any[]) {
52+
public async enqueueAfterDelay(eta: Duration | Date | number, variables?: TData) {
5353
const etaVerified = typeof eta === 'number' ? Duration.second(eta) : eta;
54-
return await this.wakaq.enqueueWithEta(this.name, args, etaVerified, this.queue);
54+
return await this.wakaq.enqueueWithEta(this.name, variables, etaVerified, this.queue);
5555
}
5656

5757
/*
@@ -60,7 +60,7 @@ export class Task<TData = unknown> {
6060
Only runs the task once per worker parent daemon, no matter the worker's concurrency.
6161
Returns the number of workers the task was sent to.
6262
*/
63-
public async broadcast(...args: any[]): Promise<number> {
64-
return await this.wakaq.broadcast(this.name, args);
63+
public async broadcast(variables?: TData): Promise<number> {
64+
return await this.wakaq.broadcast(this.name, variables);
6565
}
6666
}

src/wakaq.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ export class WakaQ {
215215
Returns the new Task with methods enqueue(), enqueueAfterDelay,
216216
and broadcast().
217217
*/
218-
public task<TData = unknown>(fn: (variables: TData) => Promise<void>, params?: RegisterTaskParams): Task<TData> {
218+
public task<TData = unknown>(fn: (variables?: TData) => Promise<void>, params?: RegisterTaskParams): Task<TData> {
219219
const task = new Task(this, fn, params?.name, params?.queue, params?.softTimeout, params?.hardTimeout, params?.maxRetries);
220220
if (this.tasks.has(task.name)) {
221221
this.logger?.error(`Duplicate task name: ${task.name}`);

src/worker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ export class WakaQWorker {
291291
}
292292
}
293293

294-
private async _executeTask(task: Task, variables: unknown, queue?: WakaQueue) {
294+
private async _executeTask(task: Task, variables?: unknown, queue?: WakaQueue) {
295295
this.logger.debug(`running with args ${variables}`);
296296
if (this.wakaq.beforeTaskStartedCallback) this.wakaq.beforeTaskStartedCallback(task);
297297
try {

0 commit comments

Comments
 (0)