All Projects → Kong → lua-resty-timer

Kong / lua-resty-timer

Licence: Apache-2.0 license
Extended timers for OpenResty

Programming Languages

perl
6916 projects
lua
6591 projects
Makefile
30231 projects

Projects that are alternatives of or similar to lua-resty-timer

Kong Docs Cn
微服务 Api 网关 Kong 最新文档中文版
Stars: ✭ 371 (+1755%)
Mutual labels:  kong, openresty
alpine-kong
alpine-kong
Stars: ✭ 15 (-25%)
Mutual labels:  kong, openresty
lua-circuit-breaker
Circuit breaker pattern in Lua
Stars: ✭ 28 (+40%)
Mutual labels:  kong
openresty-project-v0.01
🌹 基于OpenResty编写一个MVC模式的WEB项目 V0.01
Stars: ✭ 40 (+100%)
Mutual labels:  openresty
lua-casbin
An authorization library that supports access control models like ACL, RBAC, ABAC in Lua (OpenResty)
Stars: ✭ 43 (+115%)
Mutual labels:  openresty
kong-plugin-api-response-merger
Kong API response merger plugin
Stars: ✭ 14 (-30%)
Mutual labels:  kong
laravel-kong
A fluent api wrapper around Kong's API manger designed for Laravel.
Stars: ✭ 20 (+0%)
Mutual labels:  kong
meshery-kuma
Meshery Adapter for Kuma
Stars: ✭ 35 (+75%)
Mutual labels:  kong
resty-marathon-lb
基于 OpenResty 的 Marathon 服务发现 & 路由
Stars: ✭ 13 (-35%)
Mutual labels:  openresty
z-blog-openresty
程序员技术之旅-OpenResty
Stars: ✭ 25 (+25%)
Mutual labels:  openresty
lua-resty-feishu-auth
适用于 OpenResty / ngx_lua 的基于飞书组织架构的登录认证
Stars: ✭ 28 (+40%)
Mutual labels:  openresty
kong-plugins-canary
The grayscale plug-in based on gateway Kong, called Canary, meets A/B testing and dynamically switches upstream agents
Stars: ✭ 31 (+55%)
Mutual labels:  kong
kong-js-pdk
Kong PDK for Javascript and plugin server
Stars: ✭ 28 (+40%)
Mutual labels:  kong
kong-konga-example
Setup Kong + Konga + PostgreSQL using Docker Compose
Stars: ✭ 36 (+80%)
Mutual labels:  kong
lua-resty-http2
The HTTP/2 Protocol (Client Side) Implementation for OpenResty.
Stars: ✭ 73 (+265%)
Mutual labels:  openresty
lua-resty-pyf
Lua 汉字拼音首字母提取
Stars: ✭ 30 (+50%)
Mutual labels:  openresty
casper
Yelp's internal caching proxy, powered by Nginx and OpenResty at its core
Stars: ✭ 81 (+305%)
Mutual labels:  openresty
spacer
🚀Serverless function platform for Lua
Stars: ✭ 50 (+150%)
Mutual labels:  openresty
lua-twitter
A Lua twitter library that works with OpenResty or LuaSocket
Stars: ✭ 29 (+45%)
Mutual labels:  openresty
gluu-gateway
Gluu API 🚀 and Web Gateway 🎯
Stars: ✭ 29 (+45%)
Mutual labels:  kong

lua-resty-timer

Build Status

Extended timers for OpenResty. Provided recurring, cancellable, node-wide timers, beyond what the basic OpenResty timers do.

Status

This library is production ready.

Synopsis

http {
    lua_shared_dict timer_shm 1m;
    init_worker_by_lua_block {
        local timer = require("resty.timer")

        local options = {
            interval = 0.1,           -- expiry interval in seconds
            recurring = true,         -- recurring or single timer
            immediate = true,         -- initial interval will be 0
            detached = false,         -- run detached, or be garbagecollectible
            jitter = 0.1,             -- add a random interval
            expire = object.handler,  -- callback on timer expiry
            cancel = function(reason, self, param1)
                -- will be called when the timer gets cancelled
            end,
            shm_name = "timer_shm",   -- shm to use for node-wide timers
            key_name = "my_key",      -- key-name to use for node-wide timers
            sub_interval = 0.1,       -- max cross worker extra delay
        }

        local object
        object = {                            -- create some object with a timer
            count = 0,
            handler = function(self, param1)  -- the timer callback as a method
                -- do something here
                print(param1)                 --> "Param 1"
            end,

            -- create and add to object, but also pass it as 'self' to the handler
            timer = timer(options, object, "Param 1"),
        }

        -- anchor the object and timer
        _M.global_object = object     -- will be collected if not anchored

        -- cancel the timer
        object.timer:cancel()
    }
}

Description

The OpenResty timer is fairly limited, this timer adds a number of common options as parameters without having to recode (and retest) them in each project.

  • recurring timers (supported by OR as well through ngx.timer.every)

  • immediate first run for recurring timers

  • cancellable timers

  • cancel callback, called when the timer is cancelled

  • garbage collectible timers, enabling timers to (optionally) be attached to objects and automatically stop when garbage collected.

  • node-wide timers: the same timer started in each worker will still only run once across the system. If the worker running it is removed the timer will automatically be executed on another worker.

See the online LDoc documentation for the complete API.

History

Versioning is strictly based on Semantic Versioning

Releasing new versions:

  • update changelog below (PR's should be merged including a changelog entry)
  • based on changelog determine new SemVer version
  • create a new rockspec
  • render the docs using ldoc (don't do this within PR's)
  • commit as "release x.x.x" (do not include rockspec revision)
  • tag the commit with "x.x.x" (do not include rockspec revision)
  • push commit and tag
  • upload rock to luarocks: luarocks upload rockspecs/[name] --api-key=abc

unreleased

  • Feat: provide a stacktrace upon errors in the timer callback

1.1.0 (6-Nov-2020)

  • Feat: add a jitter option. This adds a random interval to distribute the timers (in case of scheduling many timers at once).

1.0.0 (21-Sep-2020)

  • Change [BREAKING]: the recurring timers are now implemented as a sleeping thread which is more efficient. Side effect is that the timer only gets rescheduled AFTER executing the handler. So if the handler is long running, then individual runs will be further apart.

0.3 (28-May-2018)

  • Feat: added cancellation callback invocation on timer being GC'ed. This changes the first argument of the cancel callback, and hence is breaking.

0.2 (12-Feb-2018) Bug fix

  • Fix: bugfix in unpack function not honoring table length parameter
  • Docs: small fixes and typo's

0.1 (22-Nov-2017) Initial release

  • Added sub_interval option to reduce delays
  • Initial upload

Copyright and License

Copyright 2017 - 2018 Kong Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].