moonlibs / xqueue

Imbue tarantool space with power of queue
15 stars 12 forks source link

xqueue doesn't work with time64 ids #5

Closed ochaton closed 5 years ago

ochaton commented 5 years ago

xqueue fails to process tasks with time64 as features.id. Version: xqueue-scm-4

Following code produces error on :release: ./xqueue.lua:1065: Task 1562001242534836139ULL not taken by any

box.cfg{ listen = "127.0.0.1:6603"  }
box.once('access:v1', function()
        box.schema.user.grant('guest', 'read,write,execute', 'universe')
end)

local format = {
        {name = "id",      type = "unsigned"},
        {name = "status",  type = "string"},
        {name = "attempt", type = "number"},

        {name = "action", type = "string"},
        {name = "attr",   type = "*"},
}
box.schema.space.create('tasks', { if_not_exists = true })
box.space.tasks:create_index('primary', { unique = true, parts = {1, 'unsigned'}, if_not_exists = true})
box.space.tasks:create_index('xq', { unique = false, parts = { 2, 'str', 1, 'unsigned' }, if_not_exists = true})

require'xqueue' (box.space.tasks, {
        fields = {
                status = 'status',
        },
        format = format,
        features = {
                id = 'time64',
                retval = 'table',
        },
})

box.space.tasks:put{ action = "hello", attr = {}, attempt = 0 }

local conn = require'net.box':connect(box.cfg.listen)
local task = conn:call("dostring", {"return box.space.tasks:take(0.1)"})
conn:call("dostring", { ("return box.space.tasks:release({%s})"):format(task.id) })

require'fiber'.yield()

local task = box.space.tasks:select()[1]
assert(task.status == "R", ("Task must be in status R not in status: %s"):format(task.status))