Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions lib/commands/takeLock-1.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,22 @@

Input:
KEYS[1] 'lock',

ARGV[1] token
ARGV[2] lock duration in milliseconds

ARGV[3] force

Output:
"OK" if lock extented succesfully.
]]
if ARGV[3] == "1" then
if redis.call("SET", KEYS[1], ARGV[1], "PX", ARGV[2]) then
return 1
else
return 0
end
end

if redis.call("SET", KEYS[1], ARGV[1], "NX", "PX", ARGV[2]) then
return 1
else
Expand Down
4 changes: 2 additions & 2 deletions lib/job.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,8 @@ Job.prototype.lockKey = function() {
Takes a lock for this job so that no other queue worker can process it at the
same time.
*/
Job.prototype.takeLock = function() {
return scripts.takeLock(this.queue, this).then(function(lock) {
Job.prototype.takeLock = function(force = false) {
return scripts.takeLock(this.queue, this, force).then(function(lock) {
return lock || false;
});
};
Expand Down
7 changes: 4 additions & 3 deletions lib/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -311,11 +311,12 @@ var scripts = {
]);
},

takeLock: function(queue, job) {
takeLock: function(queue, job, force = false) {
return queue.client.takeLock([
job.lockKey,
job.lockKey(),
queue.token,
queue.settings.lockDuration
queue.settings.lockDuration,
force ? 1 : 0
]);
},

Expand Down