Skip to content

Commit

Permalink
Dirty fix for Check both 'nil' and 'false' in redis.call return value
Browse files Browse the repository at this point in the history
This is fast and dirty applying custora#3 to the current qless master branch.
Yes, i know about qless-core :)

See also seomoz/qless-core#63
  • Loading branch information
a0s committed Jan 23, 2017
1 parent 1fb5415 commit b0d3566
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
20 changes: 10 additions & 10 deletions lib/qless/lua/qless-lib.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-- Current SHA: 525c39000dc71df53a3502491cb4daf0e1128f1d
-- Current SHA: 5e998615e96d35c55a79458a77527687ef55733d
-- This is a generated file
-------------------------------------------------------------------------------
-- Forward declarations to make everything happy
Expand Down Expand Up @@ -258,7 +258,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

This comment has been minimized.

Copy link
@moteus

moteus Feb 12, 2017

Why not just if not _tags[tag] then ....?

_tags[tag] = true
table.insert(tags, tag)
end
Expand Down Expand Up @@ -333,7 +333,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 Expand Up @@ -1144,7 +1144,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 @@ -1177,7 +1177,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 does not exist')
elseif state ~= 'running' then
error('Timeout(): Job ' .. self.jid .. ' not running')
Expand Down Expand Up @@ -1261,7 +1261,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 Expand Up @@ -1728,8 +1728,8 @@ function QlessQueue:put(now, worker, jid, klass, raw_data, delay, ...)
-- Now find what's in the original, but not the new
local original = redis.call(
'smembers', QlessJob.ns .. jid .. '-dependencies')
for _, dep in pairs(original) do
if new[dep] == nil then
for _, dep in pairs(original) do
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 Expand Up @@ -2347,8 +2347,8 @@ 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)
return tags
Expand Down
22 changes: 11 additions & 11 deletions lib/qless/lua/qless.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-- Current SHA: 525c39000dc71df53a3502491cb4daf0e1128f1d
-- Current SHA: 4bff9c77c7367b128c7474517a086cc44329cb4c
-- This is a generated file
local Qless = {
ns = 'ql:'
Expand Down Expand Up @@ -150,7 +150,7 @@ function Qless.tag(now, command, ...)

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 @@ -214,7 +214,7 @@ function Qless.cancel(...)

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 Expand Up @@ -823,7 +823,7 @@ function QlessJob:priority(priority)

local queue = redis.call('hget', QlessJob.ns .. self.jid, 'queue')

if queue == nil then
if queue == nil or queue == false then
error('Priority(): Job ' .. self.jid .. ' does not exist')
elseif queue == '' then
redis.call('hset', QlessJob.ns .. self.jid, 'priority', priority)
Expand All @@ -850,7 +850,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 does not exist')
elseif state ~= 'running' then
error('Timeout(): Job ' .. self.jid .. ' not running')
Expand Down Expand Up @@ -921,7 +921,7 @@ function QlessJob:history(now, what, item)
if count > 0 then
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 Expand Up @@ -1266,8 +1266,8 @@ 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
for _, dep in pairs(original) do
if new[dep] == nil or new[dep] == false then
redis.call('srem', QlessJob.ns .. dep .. '-dependents' , jid)
redis.call('srem', QlessJob.ns .. jid .. '-dependencies', dep)
end
Expand Down Expand Up @@ -1739,9 +1739,9 @@ function QlessRecurringJob:tag(...)
tags = cjson.decode(tags)
local _tags = {}
for i,v in ipairs(tags) do _tags[v] = true end
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)
return tags
Expand Down

0 comments on commit b0d3566

Please sign in to comment.