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

Method beforePerform

src/plugins/JobLock.ts:13–39  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

11 }
12
13 async beforePerform() {
14 const key = this.key();
15 const now = Math.round(new Date().getTime() / 1000);
16 const timeout = now + this.lockTimeout() + 1;
17
18 const lockedByMe = await this.queueObject.connection.redis.set(
19 key,
20 timeout,
21 "EX",
22 this.lockTimeout(),
23 "NX",
24 );
25 if (lockedByMe && lockedByMe.toString().toUpperCase() === "OK") {
26 return true;
27 } else {
28 const options = this.job.pluginOptions;
29 const toReEnqueue = options?.JobLock
30 ? options.JobLock.reEnqueue !== null &&
31 options.JobLock.reEnqueue !== undefined
32 ? options.JobLock.reEnqueue
33 : true
34 : true;
35
36 if (toReEnqueue) await this.reEnqueue();
37 return false;
38 }
39 }
40
41 async afterPerform() {
42 const key = this.key();

Callers

nothing calls this directly

Calls 3

keyMethod · 0.95
lockTimeoutMethod · 0.95
reEnqueueMethod · 0.95

Tested by

no test coverage detected