1 |
import DiscordClient from "../../client/Client"; |
import DiscordClient from "../../client/Client"; |
2 |
import { v4 as uuid } from 'uuid'; |
import { v4 as uuid } from 'uuid'; |
3 |
import QueuedJob, { IQueuedJob } from "../../models/QueuedJob"; |
import { IQueuedJob } from "../../models/QueuedJob"; |
4 |
|
|
5 |
export interface QueueOptions { |
export interface QueueOptions { |
6 |
runAfter?: number; |
runAfter?: number; |
35 |
console.log('Queue created: ', this.constructor.name, this.id); |
console.log('Queue created: ', this.constructor.name, this.id); |
36 |
} |
} |
37 |
|
|
38 |
|
get data() { |
39 |
|
return this.model.data; |
40 |
|
} |
41 |
|
|
42 |
async finish() { |
async finish() { |
43 |
this.client.queueManager.removeQueue(this); |
this.client.queueManager.removeQueue(this); |
44 |
console.log("Job complete: ", this.constructor.name); |
console.log("Job complete: ", this.constructor.name); |
47 |
async cancel() { |
async cancel() { |
48 |
clearTimeout(this.timeout); |
clearTimeout(this.timeout); |
49 |
await this.model.delete(); |
await this.model.delete(); |
50 |
|
this.client.queueManager.removeQueue(this); |
51 |
} |
} |
52 |
|
|
53 |
abstract execute(data?: { [key: string | number]: any }): Promise<any>; |
abstract execute(data?: { [key: string | number]: any }): Promise<any>; |
55 |
async run() { |
async run() { |
56 |
this.completed = true; |
this.completed = true; |
57 |
this.model.delete(); |
this.model.delete(); |
58 |
return await this.execute(this.model.data); |
|
59 |
|
try { |
60 |
|
return await this.execute(this.model.data); |
61 |
|
} |
62 |
|
catch (e) { |
63 |
|
console.error(`An error occurred in queue job\nJob ID: ${this.id}`, e); |
64 |
|
} |
65 |
} |
} |
66 |
} |
} |