Skip to content

Commit

Permalink
Check both nil and false in redis.call return value
Browse files Browse the repository at this point in the history
  • Loading branch information
DiEsse committed May 16, 2016
1 parent cd7f5fb commit f5257cd
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions base.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions job.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion queue.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion recurring.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit f5257cd

Please sign in to comment.