From ff6b47b0cf4c26a1a67f7cf4b50765f0b6d2971a Mon Sep 17 00:00:00 2001 From: Sam Date: Fri, 23 Mar 2018 12:57:53 +1100 Subject: [PATCH] In development mode narrative bot breaks reload --- .../{ => autoload}/jobs/bot_input.rb | 0 .../{ => autoload}/jobs/narrative_init.rb | 0 .../{ => autoload}/jobs/narrative_timeout.rb | 0 .../jobs/onceoff/grant_badges.rb | 0 .../jobs/onceoff/remap_old_bot_images.rb | 0 .../jobs/send_default_welcome_message.rb | 0 plugins/discourse-narrative-bot/plugin.rb | 28 +++++++++++++------ 7 files changed, 20 insertions(+), 8 deletions(-) rename plugins/discourse-narrative-bot/{ => autoload}/jobs/bot_input.rb (100%) rename plugins/discourse-narrative-bot/{ => autoload}/jobs/narrative_init.rb (100%) rename plugins/discourse-narrative-bot/{ => autoload}/jobs/narrative_timeout.rb (100%) rename plugins/discourse-narrative-bot/{ => autoload}/jobs/onceoff/grant_badges.rb (100%) rename plugins/discourse-narrative-bot/{ => autoload}/jobs/onceoff/remap_old_bot_images.rb (100%) rename plugins/discourse-narrative-bot/{ => autoload}/jobs/send_default_welcome_message.rb (100%) diff --git a/plugins/discourse-narrative-bot/jobs/bot_input.rb b/plugins/discourse-narrative-bot/autoload/jobs/bot_input.rb similarity index 100% rename from plugins/discourse-narrative-bot/jobs/bot_input.rb rename to plugins/discourse-narrative-bot/autoload/jobs/bot_input.rb diff --git a/plugins/discourse-narrative-bot/jobs/narrative_init.rb b/plugins/discourse-narrative-bot/autoload/jobs/narrative_init.rb similarity index 100% rename from plugins/discourse-narrative-bot/jobs/narrative_init.rb rename to plugins/discourse-narrative-bot/autoload/jobs/narrative_init.rb diff --git a/plugins/discourse-narrative-bot/jobs/narrative_timeout.rb b/plugins/discourse-narrative-bot/autoload/jobs/narrative_timeout.rb similarity index 100% rename from plugins/discourse-narrative-bot/jobs/narrative_timeout.rb rename to plugins/discourse-narrative-bot/autoload/jobs/narrative_timeout.rb diff --git a/plugins/discourse-narrative-bot/jobs/onceoff/grant_badges.rb b/plugins/discourse-narrative-bot/autoload/jobs/onceoff/grant_badges.rb similarity index 100% rename from plugins/discourse-narrative-bot/jobs/onceoff/grant_badges.rb rename to plugins/discourse-narrative-bot/autoload/jobs/onceoff/grant_badges.rb diff --git a/plugins/discourse-narrative-bot/jobs/onceoff/remap_old_bot_images.rb b/plugins/discourse-narrative-bot/autoload/jobs/onceoff/remap_old_bot_images.rb similarity index 100% rename from plugins/discourse-narrative-bot/jobs/onceoff/remap_old_bot_images.rb rename to plugins/discourse-narrative-bot/autoload/jobs/onceoff/remap_old_bot_images.rb diff --git a/plugins/discourse-narrative-bot/jobs/send_default_welcome_message.rb b/plugins/discourse-narrative-bot/autoload/jobs/send_default_welcome_message.rb similarity index 100% rename from plugins/discourse-narrative-bot/jobs/send_default_welcome_message.rb rename to plugins/discourse-narrative-bot/autoload/jobs/send_default_welcome_message.rb diff --git a/plugins/discourse-narrative-bot/plugin.rb b/plugins/discourse-narrative-bot/plugin.rb index 22dede0bbc8..477327abf49 100644 --- a/plugins/discourse-narrative-bot/plugin.rb +++ b/plugins/discourse-narrative-bot/plugin.rb @@ -1,11 +1,23 @@ # name: discourse-narrative-bot # about: Introduces staff to Discourse -# version: 0.0.1 -# authors: Nick Sahler (@nicksahler) +# version: 1.0 +# authors: Nick Sahler, Alan Tan # url: https://github.com/discourse/discourse/tree/master/plugins/discourse-narrative-bot enabled_site_setting :discourse_narrative_bot_enabled +if Rails.env == "development" + # workaround, teach reloader to reload jobs + # if we do not do this then + # + # 1. on reload rails goes and undefines Jobs::Base + # 2. as a side effect this undefines Jobs::BotInput + # 3. we have a post_edited hook that queues a job for bot input + # 4. if you are not running sidekiq in dev every time you save a post it will trigger it + # 5. but the constant can not be autoloaded + Rails.configuration.autoload_paths << File.expand_path('../autoload', __FILE__) +end + require_relative 'lib/discourse_narrative_bot/welcome_post_type_site_setting.rb' after_initialize do @@ -14,12 +26,12 @@ after_initialize do Mime::Type.register "image/svg+xml", :svg [ - '../jobs/bot_input.rb', - '../jobs/narrative_timeout.rb', - '../jobs/narrative_init.rb', - '../jobs/send_default_welcome_message.rb', - '../jobs/onceoff/grant_badges.rb', - '../jobs/onceoff/remap_old_bot_images.rb', + '../autoload/jobs/bot_input.rb', + '../autoload/jobs/narrative_timeout.rb', + '../autoload/jobs/narrative_init.rb', + '../autoload/jobs/send_default_welcome_message.rb', + '../autoload/jobs/onceoff/grant_badges.rb', + '../autoload/jobs/onceoff/remap_old_bot_images.rb', '../lib/discourse_narrative_bot/actions.rb', '../lib/discourse_narrative_bot/base.rb', '../lib/discourse_narrative_bot/new_user_narrative.rb',