Search code examples
luadaemontarantool

How to write lua-daemon for tarantool


How to write a lua-program for tarantool that will perform some tasks regularly (e.g. once per 10 minutes) in background?


Solution

  • The first way Use fibers. Fibers - is a set of instructions which are executed with cooperative multitasking. Fibers managed by the fiber package are associated with a user-supplied function called the fiber function. A fiber has three possible states: running, suspended or dead.

    Example

    fiber.create(function()
     while true do
       -- Let say you have space with tree index.
       -- Where each row index is timestamp + interval.
       -- So, here you can get lower/upper bound by current timestamp e.g.
       -- space:select{fiber.now()} -- get expired tasks
       fiber.sleep(1) -- interval
     end
    end)
    

    The second way Use expirationd - https://github.com/tarantool/expirationd