【问题标题】:How to write lua-daemon for tarantool如何为 tarantool 编写 lua-daemon
【发布时间】:2016-06-04 19:32:18
【问题描述】:

如何为 tarantool 编写一个 lua 程序,在后台定期执行一些任务(例如每 10 分钟一次)?

【问题讨论】:

    标签: lua daemon tarantool


    【解决方案1】:

    第一种方式 使用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

    【讨论】:

      猜你喜欢
      • 2020-10-07
      • 2020-09-16
      • 2018-04-21
      • 2016-07-13
      • 2022-01-27
      • 1970-01-01
      • 2020-03-10
      • 2021-01-23
      • 1970-01-01
      相关资源
      最近更新 更多