【发布时间】:2016-06-04 19:32:18
【问题描述】:
如何为 tarantool 编写一个 lua 程序,在后台定期执行一些任务(例如每 10 分钟一次)?
【问题讨论】:
如何为 tarantool 编写一个 lua 程序,在后台定期执行一些任务(例如每 10 分钟一次)?
【问题讨论】:
第一种方式 使用fibers。 Fibers - 是一组通过协作多任务执行的指令。由纤程包管理的纤程与用户提供的称为纤程功能的功能相关联。一个纤程具有三种可能的状态:运行、暂停或死亡。
例子
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)
第二种方式 使用expirationd - https://github.com/tarantool/expirationd
【讨论】: