aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/job-queue/job-queue.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib/job-queue/job-queue.ts')
-rw-r--r--server/lib/job-queue/job-queue.ts26
1 files changed, 22 insertions, 4 deletions
diff --git a/server/lib/job-queue/job-queue.ts b/server/lib/job-queue/job-queue.ts
index 3c810da98..ec601e9ea 100644
--- a/server/lib/job-queue/job-queue.ts
+++ b/server/lib/job-queue/job-queue.ts
@@ -121,11 +121,20 @@ class JobQueue {
121 return queue.add(obj.payload, jobArgs) 121 return queue.add(obj.payload, jobArgs)
122 } 122 }
123 123
124 async listForApi (state: JobState, start: number, count: number, asc?: boolean): Promise<Bull.Job[]> { 124 async listForApi (options: {
125 state: JobState,
126 start: number,
127 count: number,
128 asc?: boolean,
129 jobType: JobType
130 }): Promise<Bull.Job[]> {
131 const { state, start, count, asc, jobType } = options
125 let results: Bull.Job[] = [] 132 let results: Bull.Job[] = []
126 133
134 const filteredJobTypes = this.filterJobTypes(jobType)
135
127 // TODO: optimize 136 // TODO: optimize
128 for (const jobType of jobTypes) { 137 for (const jobType of filteredJobTypes) {
129 const queue = this.queues[ jobType ] 138 const queue = this.queues[ jobType ]
130 if (queue === undefined) { 139 if (queue === undefined) {
131 logger.error('Unknown queue %s to list jobs.', jobType) 140 logger.error('Unknown queue %s to list jobs.', jobType)
@@ -149,10 +158,12 @@ class JobQueue {
149 return results.slice(start, start + count) 158 return results.slice(start, start + count)
150 } 159 }
151 160
152 async count (state: JobState): Promise<number> { 161 async count (state: JobState, jobType?: JobType): Promise<number> {
153 let total = 0 162 let total = 0
154 163
155 for (const type of jobTypes) { 164 const filteredJobTypes = this.filterJobTypes(jobType)
165
166 for (const type of filteredJobTypes) {
156 const queue = this.queues[ type ] 167 const queue = this.queues[ type ]
157 if (queue === undefined) { 168 if (queue === undefined) {
158 logger.error('Unknown queue %s to count jobs.', type) 169 logger.error('Unknown queue %s to count jobs.', type)
@@ -180,6 +191,12 @@ class JobQueue {
180 }) 191 })
181 } 192 }
182 193
194 private filterJobTypes (jobType?: JobType) {
195 if (!jobType) return jobTypes
196
197 return jobTypes.filter(t => t === jobType)
198 }
199
183 static get Instance () { 200 static get Instance () {
184 return this.instance || (this.instance = new this()) 201 return this.instance || (this.instance = new this())
185 } 202 }
@@ -188,5 +205,6 @@ class JobQueue {
188// --------------------------------------------------------------------------- 205// ---------------------------------------------------------------------------
189 206
190export { 207export {
208 jobTypes,
191 JobQueue 209 JobQueue
192} 210}