Skip to content

Commit

Permalink
Change clock.monotonic to clock.realtime (see issue #2)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mons committed Dec 24, 2018
1 parent 3365ea9 commit e73de47
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 18 deletions.
4 changes: 3 additions & 1 deletion rockspecs/xqueue-scm-1.rockspec
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
"Usage of this version was disabled. See issue https://github.com/moonlibs/xqueue/issues/2"

package = 'xqueue'
version = 'scm-1'
source = {
url = 'git://github.com/moonlibs/xqueue.git',
branch = 'master',
branch = 'broken',
}
description = {
summary = "Package for loading external lua config",
Expand Down
22 changes: 22 additions & 0 deletions rockspecs/xqueue-scm-2.rockspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package = 'xqueue'
version = 'scm-2'
source = {
url = 'git://github.com/moonlibs/xqueue.git',
branch = 'monofix',
}
description = {
summary = "Package for loading external lua config",
homepage = 'https://github.com/moonlibs/xqueue.git',
license = 'BSD',
}
dependencies = {
'lua >= 5.1'
}
build = {
type = 'builtin',
modules = {
['xqueue'] = 'xqueue.lua'
}
}

-- vim: syntax=lua
22 changes: 22 additions & 0 deletions rockspecs/xqueue-scm-3.rockspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package = 'xqueue'
version = 'scm-3'
source = {
url = 'git://github.com/moonlibs/xqueue.git',
branch = 'master',
}
description = {
summary = "Package for loading external lua config",
homepage = 'https://github.com/moonlibs/xqueue.git',
license = 'BSD',
}
dependencies = {
'lua >= 5.1'
}
build = {
type = 'builtin',
modules = {
['xqueue'] = 'xqueue.lua'
}
}

-- vim: syntax=lua
37 changes: 20 additions & 17 deletions xqueue.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,16 @@ local clock = require 'clock'

local tuple_ctype = ffi.typeof(box.tuple.new())

-- compat
if not table.clear then
table.clear = function(t)
if type(t) ~= 'table' then
error("bad argument #1 to 'clear' (table expected, got "..(t ~= nil and type(t) or 'no value')..")",2)
end
local count = #t
for i=0, count do t[i]=nil end
return
local monotonic_max_age = 10*365*86400;

local function table_clear(t)
if type(t) ~= 'table' then
error("bad argument #1 to 'clear' (table expected, got "..(t ~= nil and type(t) or 'no value')..")",2)
end
local count = #t
for i=0, count do t[i]=nil end
return
end
-- compat

local function is_array(t)
local gen,param,state = ipairs(t)
Expand Down Expand Up @@ -223,7 +221,7 @@ local methods = {}

function M.upgrade(space,opts,depth)
depth = depth or 0
print(string.format("call on xq(%s) + %s", space.name, json.encode(opts)))
log.info("xqueue upgrade(%s,%s)", space.name, json.encode(opts))
if not opts.fields then error("opts.fields required",2) end
if opts.format then
-- todo: check if already have such format
Expand Down Expand Up @@ -409,6 +407,12 @@ function M.upgrade(space,opts,depth)
if not runat_index then
error(string.format("fields.runat requires tree index with this first field in it"),2+depth)
else
for _,t in runat_index:pairs({0},{iterator = box.index.GT}) do
if t[ self.fields.runat ] < monotonic_max_age then
error("!!! Queue contains monotonic runat values. Consider updating tasks (https://github.com/moonlibs/xqueue/issues/2)")
end
break
end
have_runat = true
end
end
Expand Down Expand Up @@ -445,7 +449,7 @@ function M.upgrade(space,opts,depth)
end
local clock = require 'clock'
gen_id = function()
local key = clock.monotonic64()
local key = clock.realtime64()
while true do
local exists = pk:get(key)
if not exists then
Expand Down Expand Up @@ -552,14 +556,13 @@ function M.upgrade(space,opts,depth)
self.space = space.id

function self.timeoffset(delta)
-- return clock.monotonic64() + tonumber64(tonumber(delta) * 1e6)
return clock.monotonic() + tonumber(delta)
return clock.realtime() + tonumber(delta)
end
function self.timeready(time)
return time < clock.monotonic()
return time < clock.realtime()
end
function self.timeremaining(time)
return time - clock.monotonic()
return time - clock.realtime()
end
-- self.NEVER = -1ULL
self.NEVER = 0
Expand Down Expand Up @@ -674,7 +677,7 @@ function M.upgrade(space,opts,depth)
end
end

table.clear(collect)
table_clear(collect)

if remaining then
if remaining >= 0 and remaining < 1 then
Expand Down

0 comments on commit e73de47

Please sign in to comment.