diff --git a/PATTERNS.md b/PATTERNS.md index 046763e..f35c422 100644 --- a/PATTERNS.md +++ b/PATTERNS.md @@ -307,5 +307,5 @@ if (nextJobdata) { **Note** By default the lock duration for a job that has been returned by ```getNextJob``` or ```moveToCompleted``` is 30 seconds, if it takes more time than that the job will be automatically -marked as stalled and depending on the max stalled options be moved back to the wait state or marked as failed. In order to avoid this you must use ```job.extendLock(duration)``` in order to give you some more time before the lock expires. The recommended is to extend the lock when half the lock time has passsed. +marked as stalled and depending on the max stalled options be moved back to the wait state or marked as failed. In order to avoid this you must use [```job.extendLock(duration)```](REFERENCE.md#jobextendlock) in order to give you some more time before the lock expires. The recommended is to extend the lock when half the lock time has passsed. diff --git a/REFERENCE.md b/REFERENCE.md index f2066b5..ddbd45a 100644 --- a/REFERENCE.md +++ b/REFERENCE.md @@ -47,8 +47,12 @@ - [Job#discard](#jobdiscard) - [Job#promote](#jobpromote) - [Job#finished](#jobfinished) - - [Job#moveToCompleted](#jobMoveToCompleted) - - [Job#moveToFailed](#jobMoveToFailed) + - [Job#moveToCompleted](#jobmovetocompleted) + - [Job#moveToFailed](#jobmovetofailed) + - [Job#lockKey](#joblockkey) + - [Job#releaseLock](#jobreleaselock) + - [Job#takeLock](#jobtakelock) + - [Job#extendLock](#jobextendlock) - [Events](#events) - [Global events](#global-events) @@ -1009,6 +1013,45 @@ Moves a job to the `failed` queue. Pulls a job from 'waiting' to 'active' and re --- +### Job#lockKey + +```ts +lockKey(): string +``` + +Return a unique key representing a lock for this Job. + +--- + +### Job#releaseLock + +```ts +releaseLock(): Promise +``` + +Releases the lock on the job. Only locks owned by the queue instance can be released. + +--- + +### Job#takeLock + +```ts +takeLock(): Promise +``` + +Takes a lock for this job so that no other queue worker can process it at the same time. + +--- + +### Job#extendLock + +```ts +extendLock(duration: number): Promise +``` + +Extend the lock for this job. The `duration` parameter specifies the lock duration in milliseconds. It will return '1' on success and '0' on failure. + +--- ## Events A queue emits also some useful events: