MCPcopy Create free account
hub / github.com/actionhero/node-resque / delByFunction

Method delByFunction

src/core/queue.ts:230–262  ·  view source on GitHub ↗

* delByFunction * * will delete all jobs in the given queue of the named function/class * * will not prevent new jobs from being added as this method is running * * will not delete jobs in the delayed queues * @param q - queue to look in * @param func - function name to delete any

(
    q: string,
    func: string,
    start: number = 0,
    stop: number = -1,
  )

Source from the content-addressed store, hash-verified

228 * @returns number of jobs deleted from queue
229 */
230 async delByFunction(
231 q: string,
232 func: string,
233 start: number = 0,
234 stop: number = -1,
235 ) {
236 const jobs = await this.connection.redis.lrange(
237 this.connection.key("queue", q),
238 start,
239 stop,
240 );
241 let numJobsDeleted: number = 0;
242 const pipeline = this.connection.redis.multi();
243
244 for (let i = 0; i < jobs.length; i++) {
245 const jobEncoded = jobs[i];
246 const { class: jobFunc } = JSON.parse(jobEncoded) as ParsedJob;
247 if (jobFunc === func) {
248 pipeline.lrem(this.connection.key("queue", q), 0, jobEncoded);
249 numJobsDeleted++;
250 }
251 }
252
253 const response = await pipeline.exec();
254
255 response?.forEach((res) => {
256 if (res[0] !== null) {
257 throw res[0];
258 }
259 });
260
261 return numJobsDeleted;
262 }
263
264 async delDelayed(q: string, func: string, args: Array<any> = []) {
265 const timestamps = [];

Callers 1

queue.tsFile · 0.80

Calls 1

keyMethod · 0.45

Tested by

no test coverage detected