From f5257cd642371c61f9d7f559902cb3685fd461ac Mon Sep 17 00:00:00 2001 From: DiEsse Date: Mon, 16 May 2016 11:22:32 +0200 Subject: [PATCH] Check both nil and false in redis.call return value --- base.lua | 4 ++-- job.lua | 6 +++--- queue.lua | 2 +- recurring.lua | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/base.lua b/base.lua index 523e5aa..5545bf9 100644 --- a/base.lua +++ b/base.lua @@ -256,7 +256,7 @@ function Qless.tag(now, command, ...) -- Otherwise, add the job to the sorted set with that tags for i=2,#arg do local tag = arg[i] - if _tags[tag] == nil then + if _tags[tag] == nil or _tags[tag] == false then _tags[tag] = true table.insert(tags, tag) end @@ -331,7 +331,7 @@ function Qless.cancel(...) -- make sure that this operation will be ok for i, jid in ipairs(arg) do for j, dep in ipairs(dependents[jid]) do - if dependents[dep] == nil then + if dependents[dep] == nil or dependents[dep] == false then error('Cancel(): ' .. jid .. ' is a dependency of ' .. dep .. ' but is not mentioned to be canceled') end diff --git a/job.lua b/job.lua index 11b52f4..39a34a4 100644 --- a/job.lua +++ b/job.lua @@ -672,7 +672,7 @@ function QlessJob:priority(priority) -- Get the queue the job is currently in, if any local queue = redis.call('hget', QlessJob.ns .. self.jid, 'queue') - if queue == nil then + if queue == nil or queue == false then -- If the job doesn't exist, throw an error error('Priority(): Job ' .. self.jid .. ' does not exist') elseif queue == '' then @@ -705,7 +705,7 @@ end function QlessJob:timeout(now) local queue_name, state, worker = unpack(redis.call('hmget', QlessJob.ns .. self.jid, 'queue', 'state', 'worker')) - if queue_name == nil then + if queue_name == nil or queue_name == false then error('Timeout(): Job ' .. self.jid .. ' does not exist') elseif state ~= 'running' then error('Timeout(): Job ' .. self.jid .. ' not running') @@ -789,7 +789,7 @@ function QlessJob:history(now, what, item) -- We'll always keep the first item around local obj = redis.call('lpop', QlessJob.ns .. self.jid .. '-history') redis.call('ltrim', QlessJob.ns .. self.jid .. '-history', -count + 2, -1) - if obj ~= nil then + if obj ~= nil and obj ~= false then redis.call('lpush', QlessJob.ns .. self.jid .. '-history', obj) end end diff --git a/queue.lua b/queue.lua index 753bbd5..4b1dd2d 100644 --- a/queue.lua +++ b/queue.lua @@ -458,7 +458,7 @@ function QlessQueue:put(now, worker, jid, klass, raw_data, delay, ...) local original = redis.call( 'smembers', QlessJob.ns .. jid .. '-dependencies') for _, dep in pairs(original) do - if new[dep] == nil then + if new[dep] == nil or new[dep] == false then -- Remove k as a dependency redis.call('srem', QlessJob.ns .. dep .. '-dependents' , jid) redis.call('srem', QlessJob.ns .. jid .. '-dependencies', dep) diff --git a/recurring.lua b/recurring.lua index 70b41f8..a81a6db 100644 --- a/recurring.lua +++ b/recurring.lua @@ -90,7 +90,7 @@ function QlessRecurringJob:tag(...) for i,v in ipairs(tags) do _tags[v] = true end -- Otherwise, add the job to the sorted set with that tags - for i=1,#arg do if _tags[arg[i]] == nil then table.insert(tags, arg[i]) end end + for i=1,#arg do if _tags[arg[i]] == nil or _tags[arg[i]] == false then table.insert(tags, arg[i]) end end tags = cjson.encode(tags) redis.call('hset', 'ql:r:' .. self.jid, 'tags', tags)