Is there a hook fired after all plugins have initialized?

Plugin Development
  • The question is in the title. Basically is there a hook fired after the hook static:app.load has 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.init after 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.init is 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?

    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?

  • 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.each is used to fire them. async.each works 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.init has finished executing?

Suggested Topics

  • 0 Votes
    3 Posts

    @josef Thank you. I'll give it a try.

  • nodebb-plugin-question-and-answer

    Unsolved Plugin Development
    0 Votes
    1 Posts

    I have installed nodebb-plugin-question-and-answer v0.7.7 on nodebb v1.13.3. but when I post a topic as question, "mark this post as correct answer" is not available. "unsolved" tag is not appearing for topic which is posted as question. Please help me with this.

  • 1 Votes
    5 Posts

    I was interested in that functionality as well, so I developed my own version of it.
    It can be found here and already is in nbbpm (can be installed from ACP by searching for nodebb-plugin-category-queue)
    It has some basic ACP (list of categories with options to queue new topics from them or not queue), and only works on new topics, not all posts (that is actually by design, as - after all - you have done the work on filtering posts already. It's just that I was looking for only sending new topics to queue)

  • 1 Votes
    9 Posts

    Ah, I've figured out the problem, it was a silly mistake. I had forgotten to rename the folder to match the plugin name. Thanks for verifying the quickstart plugin works.

  • 0 Votes
    4 Posts

    The package manager will poll npm for new changes every 10 minutes 😄

    To answer your question -- yes, the compatibility table is cached, as we don't want to be pulling data from npm in real-time (that would be a tremendous waste of resources and bandwidth for npm!)