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.
Alguém já teve tarefas rake em lib/tasks executadas duas vezes? A nossa parece executar duas vezes a partir de rake subscriptions:procourse_convert.
Olá @kimardenmiller, você chegou a descobrir a razão pela qual sua tarefa rake é executada duas vezes?
Acho que pode ter tido algo a ver com declarar o mesmo método em dois lugares, o que, creio eu, fez com que ele fosse executado duas vezes. Não verifiquei, mas dê uma olhada nisso.
EDIT: Acho que descobri como isso acontece.
Não está realmente seguindo a convenção, ou talvez demais.
O problema é se você referenciar o arquivo rake em plugin.rb, ele parece rodar duas vezes, mas a tarefa rake é incluída mesmo que você não a referencie, então não há necessidade de carregá-la durante a inicialização.
Pelo que sei, não há nenhuma lógica específica do Discourse aqui. Minha suposição seria que os arquivos de tarefa são carregados automaticamente se você definiu um ::Rails::Engine para o seu plugin?