Hi All,
I've got a situation where I need a single background thread to be running via ngx.timer.at, initialised at startup.
With multiple nginx workers init_worker_by_lua, obviously, runs in each worker and you end up with multiple recurring background threads.
So on startup every worker will write it's PID into a shared dictionary key, overwriting the previous worker.
Then the background function checks the PID for the worker it's running in matches the entry in the shared dict.
This works but the initial timer delay (the one in init_worker_by_lua) needs to be long enough for all the workers to have fully started up.
If you've got a lot of workers, a lot of config or a slow machine that time can vary dramatically so its not a great solution from that point of view.
Its also a little messy with the extra dict get and check every time the background function runs.
I was just wondering if anyone else had come up with an alternate / better solution for doing stuff like this?
Thanks!
Hamish