如何为 tarantool 编写一个在后台定期执行一些任务(例如每 10 分钟一次)的 lua 程序?
问问题
538 次
1 回答
3
第一种方式 使用纤维。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
于 2016-06-19T10:22:46.283 回答