Any support for loading rake tasks defined in plugins?

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?

1 me gusta

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.

4 Me gusta

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.

4 Me gusta

Anyone experience lib/tasks rake tasks executing twice? Ours seems to execute twice from rake subscriptions:procourse_convert.

https://github.com/ryan-hyer/discourse-subscriptions/blob/master/lib/tasks/procourse_memberships.rake

2 Me gusta

Hi @kimardenmiller , did you ever find an answer to why your rake task executes twice?

1 me gusta

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.

1 me gusta

EDITAR: Creo que he descubierto cómo sucede esto.

No sigue realmente la convención, o quizás demasiado.

El problema es si haces referencia al archivo rake en plugin.rb, parece que se ejecuta dos veces, pero la tarea rake se incluye incluso si no la haces referencia, por lo que no es necesario cargarla durante la inicialización.

@frank.manuel

1 me gusta

AFAIK no hay ninguna lógica específica de discourse aquí. Mi suposición sería que los archivos de tareas se cargan automáticamente si definiste un ::Rails::Engine para tu plugin?

1 me gusta