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.
هل واجه أي شخص تنفيذ مهام rake في lib/tasks مرتين؟ يبدو أن مهامنا تُنفَّذ مرتين عند تشغيل rake subscriptions:procourse_convert.
مرحبًا @kimardenmiller، هل عثرتِ على إجابة لسبب تنفيذ مهمة الـ rake مرتين؟
أعتقد أن الأمر قد يكون متعلقًا بإعلان نفس الدالة في مكانين، مما قد يكون سبب تشغيلها مرتين. لم يتم التأكد من ذلك، لكن تحقق من ذلك.
تحرير: أعتقد أنني اكتشفت كيف يحدث هذا.
إنه لا يتبع الاتفاقية حقًا، أو ربما يتبعها كثيرًا.
المشكلة هي إذا قمت بالإشارة إلى ملف rake في plugin.rb يبدو أنه يتم تشغيله مرتين، ولكن مهمة rake مدرجة حتى لو لم تقم بالإشارة إليها، لذلك لا حاجة لتحميلها أثناء التهيئة.
على حد علمي، لا يوجد أي منطق خاص بـ discourse هنا. تخميني هو أنه يتم تحميل ملفات المهام تلقائيًا إذا قمت بتعريف ::Rails::Engine للمكون الإضافي الخاص بك؟