Last active
August 29, 2015 14:17
-
-
Save zloidemon/221df66ddc9e9c478b23 to your computer and use it in GitHub Desktop.
Example FIFO queue in tarantool
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> curl http://tarantool.org/dist/public.key |apt-key add - | |
> echo "deb http://tarantool.org/dist/master/ubuntu/ trusty main" > /etc/apt/sources.list.d/tarantool.list | |
> apt-get update | |
> apt-get install tarantool luarocks rlwrap | |
> mkdir ~/.luarocks | |
> echo "rocks_servers = {[[http://rocks.tarantool.org/]]}" >> ~/.luarocks/config.lua | |
> luarocks install queue | |
```lua | |
#!/usr/bin/env tarantool | |
require('console').listen(33014) | |
log = require('log') | |
queue = require('queue') | |
box.cfg{ | |
listen = 33013, | |
slab_alloc_arena = 1, | |
} | |
queue:start() | |
my_fifo = queue.tube.my_fifo | |
if not my_fifo then | |
my_fifo = queue.create_tube('my_fifo', 'fifo') | |
end | |
``` | |
> chmod +x app.lua | |
> ./app.lua | |
# Next stage, connect to server console (like lua console) and manage fifo tube | |
Methods for manage tasks: | |
:put('some_data') | |
:take([timeout]) - take a task from FIFO tube | |
:bury(task_id) - bury task | |
:kick(count_of_tasks) - if somithing will wrong, you can liven up count of tasks (like after byru task) | |
:delete(task_id) - remove task from queue | |
:ack(task_id) - complite the task (also will removed from queue) | |
> rlwrap nc 127.0.0.1 33014 | |
# Create a task | |
my_fifo:put('some_data') | |
--- | |
- [ 0, 'r', 'some_data'] | |
... | |
my_task = my_fifo:take() -- take a task from FIFO tube | |
--- | |
... | |
my_task | |
--- | |
- [0, 't', 'some_data'] | |
... | |
# task with data: | |
# 1 - task id, | |
# 2 - status of task: | |
# 'r' - ready for run, | |
# 't' - taken and working with that task, | |
# '-' - complited and removed from queue, | |
# '!' - bury task, | |
# '~' - delaeyd task | |
# 3 - data field | |
# do something with data from my_task[3] and then complite task with next method | |
my_fifo:ack(my_task[1]) | |
- [0, '-', 'some_data'] | |
... | |
# More details at tests https://github.com/tarantool/queue/tree/master/t | |
# And next step i https://github.com/tarantool/http/ (in english) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
queue:start()
->queue.start()
in line #22