1 |
import DiscordClient from "../../client/Client"; |
import DiscordClient from "../../client/Client"; |
2 |
import { v4 as uuid } from 'uuid'; |
import { generate as randomstring } from 'randomstring'; |
3 |
import { IQueuedJob } from "../../models/QueuedJob"; |
import { IQueuedJob } from "../../models/QueuedJob"; |
4 |
|
|
5 |
export interface QueueOptions { |
export interface QueueOptions { |
11 |
|
|
12 |
export default abstract class Queue { |
export default abstract class Queue { |
13 |
protected completed = false; |
protected completed = false; |
14 |
protected runOn: number = 0; |
public readonly runOn: number = 0; |
15 |
public readonly id: string; |
public readonly id: string; |
16 |
protected readonly model: IQueuedJob; |
public readonly model: IQueuedJob; |
17 |
protected readonly timeout: NodeJS.Timeout; |
protected readonly timeout: NodeJS.Timeout; |
18 |
|
public readonly guild: string | undefined; |
19 |
|
|
20 |
constructor(protected client: DiscordClient, { runAfter, id, runAt, model }: QueueOptions) { |
constructor(protected client: DiscordClient, { runAfter, id, runAt, model }: QueueOptions) { |
21 |
if (runAfter !== 0 && runAfter !== 0 && !runAfter && !runAt) { |
if (runAfter !== 0 && runAfter !== 0 && !runAfter && !runAt) { |
23 |
} |
} |
24 |
|
|
25 |
this.runOn = runAfter ? Date.now() + runAfter : runAt!.getTime(); |
this.runOn = runAfter ? Date.now() + runAfter : runAt!.getTime(); |
26 |
this.id = id ?? uuid(); |
this.id = id ?? randomstring(7); |
27 |
this.model = model; |
this.model = model; |
28 |
|
this.guild = model.guild; |
29 |
|
|
30 |
const ms = this.runOn - Date.now(); |
const ms = this.runOn - Date.now(); |
31 |
|
|