Skip to content

Instantly share code, notes, and snippets.

@zloidemon
Last active August 29, 2015 14:17
Show Gist options
  • Save zloidemon/221df66ddc9e9c478b23 to your computer and use it in GitHub Desktop.
Save zloidemon/221df66ddc9e9c478b23 to your computer and use it in GitHub Desktop.
Example FIFO queue in tarantool
> 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)
@rybakit
Copy link

rybakit commented Mar 16, 2015

queue:start() -> queue.start() in line #22

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment