I tried to ngx_add_timer the postconfiguration init callback of a
module,
but it doesn’t work because ngx_event_timer_init has not yet been
called.
Is it possible to call ngx_event_timer_init before the configuration
phase ends ?
My only other alternative is to lazily add my timer in the handler
callback if not set yet (that works fine for sure, but I’m not sure
there
won’t be race which could create more timer than I need if there are
multiple workers).
Ok.
This is interesting, I may need this for mod_wsgi.
Your code in configuration callbacks will be inherited by all the worker
processes
Yes, that’s why I said I fear there is a race if the timer is added after the configuration takes place, like in my handler (there could be
a time frame between the moment I test the timer is not set and the moment
I add the timer).
I don’t think this is possible, since nginx does not uses preemption.
As an example you can use the init process callback in your ngx_module_t
definition.
Yes I’ve seen. I’ll try it to see if that works.
Is the init process callback called after the configuration takes place
and after ngx_event_tiner_init ?
It is called after configuration, and I think that it is called after
the event module has been initialized.
The other problem is that I need to get my module configuration in this
callback, which I’m not sure it is possible.
It should be possible with ngx_get_conf:
ngx_get_conf(cycle->conf_ctx, your_module);
However keep in mind that you will have a timer for each worker process,
so the cleanup code will be executed n times, unless you use shared
memory to prevent it.
My only other alternative is to lazily add my timer in the handler
callback if not set yet (that works fine for sure, but I’m not sure
there
won’t be race which could create more timer than I need if there are
multiple workers).
What do you need to do with the timer?
I need to run cleanup code every 30s or minute per main configuration
directive of my module.
Your code in configuration callbacks will be inherited by all the worker
processes
Yes, that’s why I said I fear there is a race if the timer is added after the configuration takes place, like in my handler (there could
be
a time frame between the moment I test the timer is not set and the
moment
I add the timer).
As an example you can use the init process callback in your ngx_module_t
definition.
Yes I’ve seen. I’ll try it to see if that works.
Is the init process callback called after the configuration takes
place
and after ngx_event_tiner_init ?
The other problem is that I need to get my module configuration in this
callback, which I’m not sure it is possible.
Thanks,
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.