-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtask.ts
42 lines (37 loc) · 961 Bytes
/
task.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import { QueueTag, TaskId, TaskParams, Topic } from "../types/dto";
import { IQueue } from "../interfaces/IQueue";
import { ITask } from "../interfaces/ITask";
/**
* Task for Queue consumers
*/
export class Task implements ITask {
id: TaskId;
topic: Topic;
params: TaskParams;
result: any;
waiting: boolean = false;
stalled: boolean = false;
locked: boolean = false;
completed: boolean = false;
failed: boolean = false;
error: any;
tag: string;
queue: IQueue;
consumerId?: number;
constructor(queue: IQueue, id: TaskId, topic: Topic, params: TaskParams) {
this.queue = queue;
this.id = id;
this.topic = topic;
this.params = params;
this.tag = QueueTag(topic, id);
}
remove(): void {
this.queue.remove(this);
}
complete(result: any): void {
this.queue.complete(this, result);
}
fail(error: any): void {
this.queue.failed(this, error);
}
}