I need to be able to run custom tasks against a Discourse forum. Is there any way of loading rake tasks defined in a plugin so that these can be used in production?
I think this should work. Just put them in the same directory in the plugin as where they live in core.
I’ve done this in the past with creating a rake task that runs after another but haven’t created a standalone task.
Yep this works. It didn’t appear to work for me at first hence me asking the question, but I’ve tried this again and works first time.
I added my rake task in lib/tasks in my plugin. Thought I’d confirm this works for anyone else that stumbles upon this.
Anyone experience lib/tasks rake tasks executing twice? Ours seems to execute twice from rake subscriptions:procourse_convert.
Hi @kimardenmiller , did you ever find an answer to why your rake task executes twice?
I think it might have had something to do with declaring the same method in two places, which I think caused it to run twice. Not verified, but check for that.
EDIT : Je pense avoir compris comment cela se produit.
Ce n’est pas vraiment suivre la convention, ou plutôt peut-être trop.
Le problème est si vous référencez le fichier rake dans plugin.rb, il semble s’exécuter deux fois, mais la tâche rake est incluse même si vous ne la référencez pas, il n’est donc pas nécessaire de la charger lors de l’initialisation.
Autant que je sache, il n’y a aucune logique spécifique à Discourse ici. Je suppose que les fichiers de tâches sont automatiquement chargés si vous avez défini un ::Rails::Engine pour votre plugin ?