Is there a hook fired after all plugins have initialized?
Dravere last edited by
The question is in the title. Basically is there a hook fired after the hook
static:app.loadhas been processed by all plugins. But let me give you some context what I'm trying to achieve, perhaps my design is flawed.
I'm currently in the process of writing a Prometheus exporter plugin so I can plug some forum metrics into my overall server monitoring system. But I also would like that other plugins could use my plugin to provide further metrics. So I was considering to fire two hooks from this Prometheus plugin.
static:nodebb-plugin-prometheus.init- Will fire after initialization passing in the Prometheus client to setup the metrics that should be collected.
action:nodebb-plugin-prometheus.metrics- Will fire repeatably when it is time to update the metrics. Can be configured by the user.
Obviously I only want to fire
static:nodebb-plugin-prometheus.initafter all plugins have initialized or else they might run into some kind of racing conditions. They couldn't be sure if they would be initialized whenever
static:nodebb-plugin-prometheus.initis called. Thus why I would like to fire this hook after initialization was done.
Now perhaps my idea to use hooks is the wrong approach? Should plugins interact between each other differently? Or is there another problem you see?
Theoretically, I think you can ensure your prometheus client is fired last by moving the hook priority down in the ACP plugins ordering menu (although I think that only works with templates )
Attach a "priority" value to the hook? https://github.com/NodeBB/NodeBB/blob/master/src/plugins/hooks.js#L29
I wrote that code sometime in 2013, so I don't actually remember whether a higher priority is later, or a lower priority Try it out and report back?
Dravere last edited by
A higher priority would be later in execution. The hooks are sorted here.
But the priority is mostly ignored for static and action hooks. Since
async.eachis used to fire them.
async.eachworks in parallel. Meaning that they will be started in the order of the priority but you have no guarantee that the previous hooks have completed when your hook is called.
Would you like us to fire an action hook when
static:app.inithas finished executing?