* - Enqueue a named job (defined in `jobs` to be worked by a worker) * - The job will be added to the `queueName` queue, and that queue will be worked down by available workers assigned to that queue * - args is optional, but should be an array of arguments passed to the job. Order of argument
(q: string, func: string, args: Array<any> = [])
| 80 | * - args is optional, but should be an array of arguments passed to the job. Order of arguments is maintained |
| 81 | */ |
| 82 | async enqueue(q: string, func: string, args: Array<any> = []) { |
| 83 | args = arrayify(args); |
| 84 | const job = this.jobs[func]; |
| 85 | |
| 86 | const toRun = await RunPlugins(this, "beforeEnqueue", func, q, job, args); |
| 87 | if (toRun === false) return toRun; |
| 88 | |
| 89 | const response = await this.connection.redis |
| 90 | .multi() |
| 91 | .sadd(this.connection.key("queues"), q) |
| 92 | .rpush(this.connection.key("queue", q), this.encode(q, func, args)) |
| 93 | .exec(); |
| 94 | |
| 95 | response?.forEach((res) => { |
| 96 | if (res[0] !== null) { |
| 97 | throw res[0]; |
| 98 | } |
| 99 | }); |
| 100 | |
| 101 | await RunPlugins(this, "afterEnqueue", func, q, job, args); |
| 102 | return toRun; |
| 103 | } |
| 104 | |
| 105 | /** |
| 106 | * - In ms, the unix timestamp at which this job is able to start being worked on. |