-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathinit.lua
More file actions
59 lines (50 loc) · 1.65 KB
/
init.lua
File metadata and controls
59 lines (50 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
box.cfg{
-- listen = '127.0.0.1:4221'
}
-- box.once('access:v1', function()
-- box.schema.user.grant('guest', 'read,write,execute', 'universe')
-- end)
require 'strict'.on()
-- box.once('schema',function()
local format = {
{name = "id", type = "string"},
{name = "status", type = "string"},
{name = "lock", type = "number", nullable=true},
{name = "action", type = "string"},
{name = "attr", type = "*"},
{name = "runat", type = "number"},
}
box.schema.space.create('tasks', { if_not_exists = true, format = format })
box.space.tasks:create_index('primary', { unique = true, parts = {'id'}, if_not_exists = true})
box.space.tasks:create_index('xq', { unique = false, parts = { 'status', 'id' }, if_not_exists = true})
box.space.tasks:create_index('lock', { unique = false, parts = { 'lock', 'status', 'id' }, if_not_exists = true})
box.space.tasks:create_index('runat', { unique = false, parts = { 'runat', 'id' }, if_not_exists = true})
-- end)
if not package.path:match('%.%./%?%.lua;') then
package.path = '../?.lua;' .. package.path
end
require 'xqueue' ( box.space.tasks, {
debug = true;
fields = {
status = 'status';
lock = 'lock';
runat = 'runat';
};
features = {
id = 'uuid',
delayed = true,
ttl = true,
};
workers = 0;
worker = function(task)
print(require'fiber'.self().id(), "got task",task.id, require'yaml'.encode(box.space.tasks:select()))
require'fiber'.sleep(10)
end;
} )
print(require'yaml'.encode(box.space.tasks:select()))
-- for i = 1, 5 do
-- local t = box.space.tasks:put{ lock=1, action = "doit", attr = {} }
-- print('inserted', t.id, t.status)
-- end
require'console'.start()
os.exit()