| 262 | } |
| 263 | |
| 264 | async delDelayed(q: string, func: string, args: Array<any> = []) { |
| 265 | const timestamps = []; |
| 266 | args = arrayify(args); |
| 267 | const search = this.encode(q, func, args); |
| 268 | |
| 269 | const members = await this.connection.redis.smembers( |
| 270 | this.connection.key("timestamps:" + search), |
| 271 | ); |
| 272 | |
| 273 | const pipeline = this.connection.redis.multi(); |
| 274 | |
| 275 | for (const i in members) { |
| 276 | const key = members[i]; |
| 277 | const count = await this.connection.redis.lrem( |
| 278 | this.connection.key(key), |
| 279 | 0, |
| 280 | search, |
| 281 | ); |
| 282 | if (count > 0) { |
| 283 | timestamps.push(key.split(":")[key.split(":").length - 1]); |
| 284 | pipeline.srem(this.connection.key("timestamps:" + search), key); |
| 285 | } |
| 286 | } |
| 287 | |
| 288 | const response = await pipeline.exec(); |
| 289 | |
| 290 | response?.forEach((res) => { |
| 291 | if (res[0] !== null) { |
| 292 | throw res[0]; |
| 293 | } |
| 294 | }); |
| 295 | |
| 296 | return timestamps.map((t) => parseInt(t, 10)); |
| 297 | } |
| 298 | |
| 299 | /** |
| 300 | * - learn the timestamps at which a job is scheduled to be run. |