{"id":13777338,"url":"https://github.com/Kong/lua-resty-worker-manager","last_synced_at":"2025-05-11T11:33:25.170Z","repository":{"id":66527155,"uuid":"112213694","full_name":"Kong/lua-resty-worker-manager","owner":"Kong","description":"Tracks worker processes and nodes starting/restarting/reloading/stopping","archived":false,"fork":false,"pushed_at":"2021-09-15T14:37:49.000Z","size":22,"stargazers_count":4,"open_issues_count":0,"forks_count":3,"subscribers_count":33,"default_branch":"master","last_synced_at":"2024-04-15T03:18:28.981Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://kong.github.io/lua-resty-worker-manager/topics/readme.md.html","language":"Perl","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Kong.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2017-11-27T15:29:51.000Z","updated_at":"2022-09-27T05:07:38.000Z","dependencies_parsed_at":"2023-05-18T01:46:49.409Z","dependency_job_id":null,"html_url":"https://github.com/Kong/lua-resty-worker-manager","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kong%2Flua-resty-worker-manager","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kong%2Flua-resty-worker-manager/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kong%2Flua-resty-worker-manager/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kong%2Flua-resty-worker-manager/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Kong","download_url":"https://codeload.github.com/Kong/lua-resty-worker-manager/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225043096,"owners_count":17411927,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-03T18:00:41.829Z","updated_at":"2024-11-17T13:30:40.151Z","avatar_url":"https://github.com/Kong.png","language":"Perl","readme":"# lua-resty-worker-manager\n\n\nTracks workers and nodes starting/restarting/reloading/stopping.\n\n## Status\n\nThis library is still under early development, and currently lacks tests.\n\n## Synopsis\n\n```nginx\nhttp {\n    lua_shared_dict my_shm 5m;\n\n    init_by_lua_block {\n        require(\"resty.worker.manager\").on_init_by_lua({\n                shm = \"my_shm\",\n                interval = 10,  -- worker heartbeat interval in seconds\n                failed = 5, -- max heartbeat overrun to detect crashed worker, in seconds\n            },\n            function(master_id, n_prev, n_mine, n_next)\n                ngx.log(ngx.ERR, \"================================= Master start =================================\")\n                if n_prev == nil then\n                    -- no previous master, so this is nginx start or restart\n                else\n                    -- previous master, so we are reloading\n                    if n_prev == 0 then\n                        -- all old workers have already exited\n                    else\n                        -- stil 'n_prev' old workers are running\n                    end\n                end\n            end,\n            function(master_id, n_prev, n_mine, n_next)\n                ngx.log(ngx.ERR, \"================================= Master exit ==================================\")\n                if n_next == nil then\n                    -- we are stopping this nginx node\n                else\n                    -- we are only reloading, all our workers have already exited, this code\n                    -- runs on the last worker.\n                    if n_next \u003e 0 then\n                        -- new workers have already been initialized\n                    end\n                end\n            end)\n        kong = require 'kong'\n        kong.init()\n    }\n\n    init_worker_by_lua_block {\n        require(\"resty.worker.manager\").on_init_worker_by_lua(\n            function(worker_id, n_prev, n_mine, n_next)\n                ngx.log(ngx.ERR, \"--------------------------------- Worker start ---------------------------------\")\n                if n_mine == 1 then\n                    -- I'm the very first worker to start\n                elseif n_mine \u003e ngx.worker.count() then\n                    -- a worker failed and exited, this a respawned worker.\n                    -- After the failed worker heart-beat times out then\n                    -- n_mine == ngx.worker.count() again\n                else\n                    -- other workers have started before me\n                end\n            end,\n            function(worker_id, n_prev, n_mine, n_next)\n                ngx.log(ngx.ERR, \"--------------------------------- Worker exit ----------------------------------\")\n                if n_next then\n                    -- we are reloading nginx\n                end\n                if n_mine == 1 then\n                    -- I'm the very last worker to exit\n                else\n                    -- I'm not the last worker, there are more\n                end\n            end)\n        kong.init_worker()\n    }\n}\n```\n\n## Description\n\nWithin Nginx/OpenResty it is not always easy to detect workers starting/stopping\nand to distinguish between starting/restarting/reloading/stopping the server.\nThat is what this module does. It detects those, and allows to run synchonized\ncode (protected within a lock) when it does\n\nSee the [online LDoc documentation](http://kong.github.io/lua-resty-worker-manager)\nfor the complete API.\n\n## History\n\n### 0.1 (xx-Nov-xx) Initial release\n\n  * Initial upload\n\n## Copyright and License\n\n```\nCopyright 2017 Kong Inc.\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n   http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n```\n\n","funding_links":[],"categories":["Libraries"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FKong%2Flua-resty-worker-manager","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FKong%2Flua-resty-worker-manager","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FKong%2Flua-resty-worker-manager/lists"}