Module resty.worker.manager
Worker manager.
This module allows to track nginx workers starting/exiting, as well as detecting Node start/reload/exit.
All callbacks run within a lock. So while the callback is processing no other processes can start/stop. They all run unprotected so wrap them in a pcall if required. The callbacks all have the same function signature:
function(id, n_prev, n_mine, n_next)
idis a unique id for the currently starting/stopping worker or master process.n_prev: the current number of running workers in the previous master. Will benilif there is no previous master exiting.n_mine: the current number of running workers in the master to which the current master or worker belongs.n_next: the current number of running workers in the next master (if already started). Will benilif there is no new master starting.
Info:
- Copyright: 2017 Kong Inc.
- License: Apache 2.0
- Author: Thijs Schreijer
Functions
| on_init_by_lua (opts, master_start_cb, master_exit_cb) | Initializer. |
| on_init_worker_by_lua (start_cb, exit_cb) | Initialize worker. |
Functions
- on_init_by_lua (opts, master_start_cb, master_exit_cb)
-
Initializer. MUST be called in the
init_by_luaphase. Theoptstable supports the following options:shm: (required) name of the shm to use for synchonizationinterval: (optional) heartbeat interval in seconds (default = 10)failed: (optional) max heartbeat overrun (in seconds) before a worker is considered crashed (default = 5)
Parameters:
- opts Options table
- master_start_cb callback called when the master process starts
- master_exit_cb callback called when the master process exits
Returns:
-
success, err
- on_init_worker_by_lua (start_cb, exit_cb)
-
Initialize worker.
MUST be called in the
init_worker_by_luaphase.Parameters:
- start_cb callback called when the worker process starts
- exit_cb callback called when the worker process exits
Returns:
-
success, err