From 803feefd54c6159b571888628a55d9aaebf9ea82 Mon Sep 17 00:00:00 2001 From: Sam Date: Mon, 4 May 2015 12:21:00 +1000 Subject: [PATCH] MessageBus handles readonly redis now, no need to wrap it --- app/controllers/admin/users_controller.rb | 6 +- app/models/category.rb | 2 +- app/models/color_scheme.rb | 2 +- app/models/post.rb | 2 +- app/models/post_action.rb | 2 +- app/models/queued_post.rb | 2 +- app/models/site_customization.rb | 10 +-- app/models/topic.rb | 4 +- app/models/topic_tracking_state.rb | 8 +- app/models/topic_user.rb | 8 +- app/models/user.rb | 4 +- app/models/user_action.rb | 4 +- app/services/user_destroyer.rb | 2 +- config/initializers/04-discourse_bus.rb | 3 - config/initializers/04-message_bus.rb | 47 ++++++++++++ lib/auth/default_current_user_provider.rb | 2 +- lib/backup_restore/backup_restore.rb | 4 +- lib/backup_restore/backuper.rb | 2 +- lib/backup_restore/restorer.rb | 2 +- lib/discourse.rb | 14 ++-- lib/discourse_bus.rb | 73 ------------------- lib/distributed_cache.rb | 4 +- lib/message_bus_diags.rb | 8 +- lib/site_setting_extension.rb | 8 +- plugins/poll/plugin.rb | 8 +- .../spec/controllers/polls_controller_spec.rb | 6 +- spec/components/discourse_spec.rb | 4 +- spec/components/post_creator_spec.rb | 6 +- spec/models/topic_spec.rb | 4 +- 29 files changed, 111 insertions(+), 140 deletions(-) delete mode 100644 config/initializers/04-discourse_bus.rb create mode 100644 config/initializers/04-message_bus.rb delete mode 100644 lib/discourse_bus.rb diff --git a/app/controllers/admin/users_controller.rb b/app/controllers/admin/users_controller.rb index 6b8a0fca4..c1194709f 100644 --- a/app/controllers/admin/users_controller.rb +++ b/app/controllers/admin/users_controller.rb @@ -54,7 +54,7 @@ class Admin::UsersController < Admin::AdminController @user.suspended_at = DateTime.now @user.save! StaffActionLogger.new(current_user).log_user_suspend(@user, params[:reason]) - DiscourseBus.publish "/logout", @user.id, user_ids: [@user.id] + MessageBus.publish "/logout", @user.id, user_ids: [@user.id] render nothing: true end @@ -71,7 +71,7 @@ class Admin::UsersController < Admin::AdminController if @user @user.auth_token = nil @user.save! - DiscourseBus.publish "/logout", @user.id, user_ids: [@user.id] + MessageBus.publish "/logout", @user.id, user_ids: [@user.id] render json: success_json else render json: {error: I18n.t('admin_js.admin.users.id_not_found')}, status: 404 @@ -350,7 +350,7 @@ class Admin::UsersController < Admin::AdminController end def refresh_browser(user) - DiscourseBus.publish "/file-change", ["refresh"], user_ids: [user.id] + MessageBus.publish "/file-change", ["refresh"], user_ids: [user.id] end end diff --git a/app/models/category.rb b/app/models/category.rb index de46c3e19..bfaf2f001 100644 --- a/app/models/category.rb +++ b/app/models/category.rb @@ -222,7 +222,7 @@ SQL end def publish_categories_list - DiscourseBus.publish('/categories', {categories: ActiveModel::ArraySerializer.new(Category.latest).as_json}) + MessageBus.publish('/categories', {categories: ActiveModel::ArraySerializer.new(Category.latest).as_json}) end def parent_category_validator diff --git a/app/models/color_scheme.rb b/app/models/color_scheme.rb index a575db8fd..d4a1b02de 100644 --- a/app/models/color_scheme.rb +++ b/app/models/color_scheme.rb @@ -97,7 +97,7 @@ class ColorScheme < ActiveRecord::Base end def publish_discourse_stylesheet - DiscourseBus.publish("/discourse_stylesheet", self.name) + MessageBus.publish("/discourse_stylesheet", self.name) DiscourseStylesheets.cache.clear end diff --git a/app/models/post.rb b/app/models/post.rb index 9ddf014ea..281b6a3d4 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -97,7 +97,7 @@ class Post < ActiveRecord::Base # special failsafe for posts missing topics # consistency checks should fix, but message # is safe to skip - DiscourseBus.publish("/topic/#{topic_id}", { + MessageBus.publish("/topic/#{topic_id}", { id: id, post_number: post_number, updated_at: Time.now, diff --git a/app/models/post_action.rb b/app/models/post_action.rb index 72722d4e1..5fc133012 100644 --- a/app/models/post_action.rb +++ b/app/models/post_action.rb @@ -56,7 +56,7 @@ class PostAction < ActiveRecord::Base $redis.set('posts_flagged_count', posts_flagged_count) user_ids = User.staff.pluck(:id) - DiscourseBus.publish('/flagged_counts', { total: posts_flagged_count }, { user_ids: user_ids }) + MessageBus.publish('/flagged_counts', { total: posts_flagged_count }, { user_ids: user_ids }) end def self.flagged_posts_count diff --git a/app/models/queued_post.rb b/app/models/queued_post.rb index 5f3fad170..39c51a354 100644 --- a/app/models/queued_post.rb +++ b/app/models/queued_post.rb @@ -42,7 +42,7 @@ class QueuedPost < ActiveRecord::Base def self.broadcast_new! msg = { post_queue_new_count: QueuedPost.new_count } - DiscourseBus.publish('/queue_counts', msg, user_ids: User.staff.pluck(:id)) + MessageBus.publish('/queue_counts', msg, user_ids: User.staff.pluck(:id)) end def reject!(rejected_by) diff --git a/app/models/site_customization.rb b/app/models/site_customization.rb index aff6ae159..790f15ca4 100644 --- a/app/models/site_customization.rb +++ b/app/models/site_customization.rb @@ -34,11 +34,11 @@ class SiteCustomization < ActiveRecord::Base after_save do remove_from_cache! if stylesheet_changed? || mobile_stylesheet_changed? - DiscourseBus.publish "/file-change/#{key}", SecureRandom.hex - DiscourseBus.publish "/file-change/#{SiteCustomization::ENABLED_KEY}", SecureRandom.hex + MessageBus.publish "/file-change/#{key}", SecureRandom.hex + MessageBus.publish "/file-change/#{SiteCustomization::ENABLED_KEY}", SecureRandom.hex end - DiscourseBus.publish "/header-change/#{key}", header if header_changed? - DiscourseBus.publish "/footer-change/#{key}", footer if footer_changed? + MessageBus.publish "/header-change/#{key}", header if header_changed? + MessageBus.publish "/footer-change/#{key}", footer if footer_changed? DiscourseStylesheets.cache.clear end @@ -109,7 +109,7 @@ class SiteCustomization < ActiveRecord::Base end def self.remove_from_cache!(key, broadcast = true) - DiscourseBus.publish('/site_customization', key: key) if broadcast + MessageBus.publish('/site_customization', key: key) if broadcast clear_cache! end diff --git a/app/models/topic.rb b/app/models/topic.rb index 899246f8c..8dc8df8bb 100644 --- a/app/models/topic.rb +++ b/app/models/topic.rb @@ -641,7 +641,7 @@ class Topic < ActiveRecord::Base self.add_moderator_post(user, I18n.t("archetypes.banner.message.make")) self.save - DiscourseBus.publish('/site/banner', banner) + MessageBus.publish('/site/banner', banner) end def remove_banner!(user) @@ -649,7 +649,7 @@ class Topic < ActiveRecord::Base self.add_moderator_post(user, I18n.t("archetypes.banner.message.remove")) self.save - DiscourseBus.publish('/site/banner', nil) + MessageBus.publish('/site/banner', nil) end def banner diff --git a/app/models/topic_tracking_state.rb b/app/models/topic_tracking_state.rb index 61ca7506e..0bf3fa709 100644 --- a/app/models/topic_tracking_state.rb +++ b/app/models/topic_tracking_state.rb @@ -33,7 +33,7 @@ class TopicTrackingState group_ids = topic.category && topic.category.secure_group_ids - DiscourseBus.publish("/new", message.as_json, group_ids: group_ids) + MessageBus.publish("/new", message.as_json, group_ids: group_ids) publish_read(topic.id, 1, topic.user_id) end @@ -51,7 +51,7 @@ class TopicTrackingState } group_ids = topic.category && topic.category.secure_group_ids - DiscourseBus.publish("/latest", message.as_json, group_ids: group_ids) + MessageBus.publish("/latest", message.as_json, group_ids: group_ids) end def self.publish_unread(post) @@ -77,7 +77,7 @@ class TopicTrackingState } } - DiscourseBus.publish("/unread/#{tu.user_id}", message.as_json, group_ids: group_ids) + MessageBus.publish("/unread/#{tu.user_id}", message.as_json, group_ids: group_ids) end end @@ -97,7 +97,7 @@ class TopicTrackingState } } - DiscourseBus.publish("/unread/#{user_id}", message.as_json, user_ids: [user_id]) + MessageBus.publish("/unread/#{user_id}", message.as_json, user_ids: [user_id]) end diff --git a/app/models/topic_user.rb b/app/models/topic_user.rb index 87df2c633..2611039f3 100644 --- a/app/models/topic_user.rb +++ b/app/models/topic_user.rb @@ -40,7 +40,7 @@ class TopicUser < ActiveRecord::Base notifications_reason_id: reason ) - DiscourseBus.publish("/topic/#{topic_id}", { + MessageBus.publish("/topic/#{topic_id}", { notification_level_change: notification_levels[:tracking], notifications_reason_id: reason }, user_ids: [user_id]) @@ -113,7 +113,7 @@ class TopicUser < ActiveRecord::Base end if attrs[:notification_level] - DiscourseBus.publish("/topic/#{topic_id}", + MessageBus.publish("/topic/#{topic_id}", {notification_level_change: attrs[:notification_level]}, user_ids: [user_id]) end @@ -196,7 +196,7 @@ class TopicUser < ActiveRecord::Base end if before != after - DiscourseBus.publish("/topic/#{topic_id}", {notification_level_change: after}, user_ids: [user.id]) + MessageBus.publish("/topic/#{topic_id}", {notification_level_change: after}, user_ids: [user.id]) end end @@ -219,7 +219,7 @@ class TopicUser < ActiveRecord::Base WHERE ftu.user_id = :user_id and ftu.topic_id = :topic_id)", args) - DiscourseBus.publish("/topic/#{topic_id}", {notification_level_change: args[:new_status]}, user_ids: [user.id]) + MessageBus.publish("/topic/#{topic_id}", {notification_level_change: args[:new_status]}, user_ids: [user.id]) end end diff --git a/app/models/user.rb b/app/models/user.rb index 19431c099..0660f0bc0 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -206,7 +206,7 @@ class User < ActiveRecord::Base # tricky, we need our bus to be subscribed from the right spot def sync_notification_channel_position @unread_notifications_by_type = nil - self.notification_channel_position = DiscourseBus.last_id("/notification/#{id}") + self.notification_channel_position = MessageBus.last_id("/notification/#{id}") end def invited_by @@ -298,7 +298,7 @@ class User < ActiveRecord::Base end def publish_notifications_state - DiscourseBus.publish("/notification/#{id}", + MessageBus.publish("/notification/#{id}", {unread_notifications: unread_notifications, unread_private_messages: unread_private_messages, total_unread_notifications: total_unread_notifications}, diff --git a/app/models/user_action.rb b/app/models/user_action.rb index 11926badf..0e979991c 100644 --- a/app/models/user_action.rb +++ b/app/models/user_action.rb @@ -224,7 +224,7 @@ SQL end if action.user - DiscourseBus.publish("/users/#{action.user.username.downcase}", action.id, user_ids: [user_id], group_ids: group_ids) + MessageBus.publish("/users/#{action.user.username.downcase}", action.id, user_ids: [user_id], group_ids: group_ids) end action @@ -240,7 +240,7 @@ SQL require_parameters(hash, :action_type, :user_id, :acting_user_id, :target_topic_id, :target_post_id) if action = UserAction.find_by(hash.except(:created_at)) action.destroy - DiscourseBus.publish("/user/#{hash[:user_id]}", {user_action_id: action.id, remove: true}) + MessageBus.publish("/user/#{hash[:user_id]}", {user_action_id: action.id, remove: true}) end update_like_count(hash[:user_id], hash[:action_type], -1) diff --git a/app/services/user_destroyer.rb b/app/services/user_destroyer.rb index a6dd4da49..2b70d181c 100644 --- a/app/services/user_destroyer.rb +++ b/app/services/user_destroyer.rb @@ -80,7 +80,7 @@ class UserDestroyer end StaffActionLogger.new(@actor == user ? Discourse.system_user : @actor).log_user_deletion(user, opts.slice(:context)) - DiscourseBus.publish "/file-change", ["refresh"], user_ids: [user.id] + MessageBus.publish "/file-change", ["refresh"], user_ids: [user.id] end end end diff --git a/config/initializers/04-discourse_bus.rb b/config/initializers/04-discourse_bus.rb deleted file mode 100644 index 57b44c675..000000000 --- a/config/initializers/04-discourse_bus.rb +++ /dev/null @@ -1,3 +0,0 @@ -require_dependency 'discourse_bus' - -DiscourseBus.start! diff --git a/config/initializers/04-message_bus.rb b/config/initializers/04-message_bus.rb new file mode 100644 index 000000000..7ada7b9ff --- /dev/null +++ b/config/initializers/04-message_bus.rb @@ -0,0 +1,47 @@ +MessageBus.site_id_lookup do + RailsMultisite::ConnectionManagement.current_db +end + +MessageBus.extra_response_headers_lookup do |env| + { + "Access-Control-Allow-Origin" => Discourse.base_url_no_prefix, + "Access-Control-Allow-Methods" => "GET, POST", + "Access-Control-Allow-Headers" => "X-SILENCE-LOGGER, X-Shared-Session-Key" + } +end + +MessageBus.user_id_lookup do |env| + user = CurrentUser.lookup_from_env(env) + user.id if user +end + +MessageBus.group_ids_lookup do |env| + user = CurrentUser.lookup_from_env(env) + user.groups.select('groups.id').map{|g| g.id} if user +end + +MessageBus.on_connect do |site_id| + RailsMultisite::ConnectionManagement.establish_connection(db: site_id) +end + +MessageBus.on_disconnect do |site_id| + ActiveRecord::Base.connection_handler.clear_active_connections! +end + +# Point at our redis +MessageBus.redis_config = YAML.load(ERB.new(File.new("#{Rails.root}/config/redis.yml").read).result)[Rails.env].symbolize_keys + +MessageBus.long_polling_enabled = SiteSetting.enable_long_polling +MessageBus.long_polling_interval = SiteSetting.long_polling_interval + +MessageBus.is_admin_lookup do |env| + user = CurrentUser.lookup_from_env(env) + if user && user.admin + true + else + false + end +end + +MessageBus.cache_assets = !Rails.env.development? +MessageBus.enable_diagnostics diff --git a/lib/auth/default_current_user_provider.rb b/lib/auth/default_current_user_provider.rb index 19a3084bb..1e5cec773 100644 --- a/lib/auth/default_current_user_provider.rb +++ b/lib/auth/default_current_user_provider.rb @@ -85,7 +85,7 @@ class Auth::DefaultCurrentUserProvider if SiteSetting.log_out_strict && (user = current_user) user.auth_token = nil user.save! - DiscourseBus.publish "/logout", user.id, user_ids: [user.id] + MessageBus.publish "/logout", user.id, user_ids: [user.id] end cookies[TOKEN_COOKIE] = nil end diff --git a/lib/backup_restore/backup_restore.rb b/lib/backup_restore/backup_restore.rb index c419e8299..c917be31b 100644 --- a/lib/backup_restore/backup_restore.rb +++ b/lib/backup_restore/backup_restore.rb @@ -62,7 +62,7 @@ module BackupRestore def self.logs id = start_logs_message_id - DiscourseBus.backlog(LOGS_CHANNEL, id).map { |m| m.data } + MessageBus.backlog(LOGS_CHANNEL, id).map { |m| m.data } end def self.current_version @@ -142,7 +142,7 @@ module BackupRestore end def self.save_start_logs_message_id - id = DiscourseBus.last_id(LOGS_CHANNEL) + id = MessageBus.last_id(LOGS_CHANNEL) $redis.set(start_logs_message_id_key, id) end diff --git a/lib/backup_restore/backuper.rb b/lib/backup_restore/backuper.rb index 3c5106857..a1eff0221 100644 --- a/lib/backup_restore/backuper.rb +++ b/lib/backup_restore/backuper.rb @@ -336,7 +336,7 @@ module BackupRestore def publish_log(message, timestamp) return unless @publish_to_message_bus data = { timestamp: timestamp, operation: "backup", message: message } - DiscourseBus.publish(BackupRestore::LOGS_CHANNEL, data, user_ids: [@user_id]) + MessageBus.publish(BackupRestore::LOGS_CHANNEL, data, user_ids: [@user_id]) end def save_log(message, timestamp) diff --git a/lib/backup_restore/restorer.rb b/lib/backup_restore/restorer.rb index 0599a2c03..bccd2e607 100644 --- a/lib/backup_restore/restorer.rb +++ b/lib/backup_restore/restorer.rb @@ -354,7 +354,7 @@ module BackupRestore def publish_log(message, timestamp) return unless @publish_to_message_bus data = { timestamp: timestamp, operation: "restore", message: message } - DiscourseBus.publish(BackupRestore::LOGS_CHANNEL, data, user_ids: [@user_id]) + MessageBus.publish(BackupRestore::LOGS_CHANNEL, data, user_ids: [@user_id]) end def save_log(message, timestamp) diff --git a/lib/discourse.rb b/lib/discourse.rb index 44d708e2a..653703779 100644 --- a/lib/discourse.rb +++ b/lib/discourse.rb @@ -119,10 +119,10 @@ module Discourse digest = Digest::MD5.hexdigest(ActionView::Base.assets_manifest.assets.values.sort.join) channel = "/global/asset-version" - message = DiscourseBus.last_message(channel) + message = MessageBus.last_message(channel) unless message && message.data == digest - DiscourseBus.publish channel, digest + MessageBus.publish channel, digest end digest end @@ -193,7 +193,7 @@ module Discourse def self.enable_readonly_mode $redis.set(readonly_mode_key, 1) - DiscourseBus.publish(readonly_channel, true) + MessageBus.publish(readonly_channel, true) keep_readonly_mode true end @@ -210,7 +210,7 @@ module Discourse def self.disable_readonly_mode $redis.del(readonly_mode_key) - DiscourseBus.publish(readonly_channel, false) + MessageBus.publish(readonly_channel, false) true end @@ -221,9 +221,9 @@ module Discourse def self.request_refresh! # Causes refresh on next click for all clients # - # This is better than `DiscourseBus.publish "/file-change", ["refresh"]` because + # This is better than `MessageBus.publish "/file-change", ["refresh"]` because # it spreads the refreshes out over a time period - DiscourseBus.publish '/global/asset-version', 'clobber' + MessageBus.publish '/global/asset-version', 'clobber' end def self.git_version @@ -298,7 +298,7 @@ module Discourse def self.after_fork current_db = RailsMultisite::ConnectionManagement.current_db RailsMultisite::ConnectionManagement.establish_connection(db: current_db) - DiscourseBus.after_fork + MessageBus.after_fork SiteSetting.after_fork $redis.client.reconnect Rails.cache.reconnect diff --git a/lib/discourse_bus.rb b/lib/discourse_bus.rb deleted file mode 100644 index cb39db0df..000000000 --- a/lib/discourse_bus.rb +++ /dev/null @@ -1,73 +0,0 @@ -# Proxies MessageBus and noops READONLY errors. -module DiscourseBus - - def self.start! - MessageBus.site_id_lookup do - RailsMultisite::ConnectionManagement.current_db - end - - MessageBus.extra_response_headers_lookup do |env| - { - "Access-Control-Allow-Origin" => Discourse.base_url_no_prefix, - "Access-Control-Allow-Methods" => "GET, POST", - "Access-Control-Allow-Headers" => "X-SILENCE-LOGGER, X-Shared-Session-Key" - } - end - - MessageBus.user_id_lookup do |env| - user = CurrentUser.lookup_from_env(env) - user.id if user - end - - MessageBus.group_ids_lookup do |env| - user = CurrentUser.lookup_from_env(env) - user.groups.select('groups.id').map{|g| g.id} if user - end - - MessageBus.on_connect do |site_id| - RailsMultisite::ConnectionManagement.establish_connection(db: site_id) - end - - MessageBus.on_disconnect do |site_id| - ActiveRecord::Base.connection_handler.clear_active_connections! - end - - # Point at our redis - MessageBus.redis_config = YAML.load(ERB.new(File.new("#{Rails.root}/config/redis.yml").read).result)[Rails.env].symbolize_keys - - MessageBus.long_polling_enabled = SiteSetting.enable_long_polling - MessageBus.long_polling_interval = SiteSetting.long_polling_interval - - MessageBus.is_admin_lookup do |env| - user = CurrentUser.lookup_from_env(env) - if user && user.admin - true - else - false - end - end - - MessageBus.cache_assets = !Rails.env.development? - MessageBus.enable_diagnostics - end - - def self.proxy_readonly(*methods) - methods.each do |name| - define_singleton_method(name) do |*args, &block| - DiscourseRedis.ignore_readonly { MessageBus.send(name, *args, &block) } - end - end - end - - proxy_readonly :publish, - :subscribe, - :unsubscribe, - :last_id, - :last_message, - :backlog, - :after_fork, - :on_connect, - :on_disconnect, - :track_publish - -end diff --git a/lib/distributed_cache.rb b/lib/distributed_cache.rb index 44cd2744f..28307e375 100644 --- a/lib/distributed_cache.rb +++ b/lib/distributed_cache.rb @@ -51,7 +51,7 @@ class DistributedCache return if @subscribed @lock.synchronize do return if @subscribed - DiscourseBus.subscribe(channel_name) do |message| + MessageBus.subscribe(channel_name) do |message| @lock.synchronize do process_message(message) end @@ -63,7 +63,7 @@ class DistributedCache def self.publish(hash, message) message[:origin] = hash.identity message[:hash_key] = hash.key - DiscourseBus.publish(channel_name, message, { user_ids: [-1] }) + MessageBus.publish(channel_name, message, { user_ids: [-1] }) end def self.set(hash, key, value) diff --git a/lib/message_bus_diags.rb b/lib/message_bus_diags.rb index 1ef448bf7..3d7f795dc 100644 --- a/lib/message_bus_diags.rb +++ b/lib/message_bus_diags.rb @@ -11,7 +11,7 @@ class MessageBusDiags end def self.establish_peer_names - DiscourseBus.publish "/server-name", {channel: "/server-name-reply/#{my_id}"} + MessageBus.publish "/server-name", {channel: "/server-name-reply/#{my_id}"} end def self.seen_hosts @@ -20,12 +20,12 @@ class MessageBusDiags unless @subscribed - DiscourseBus.subscribe "/server-name-reply/#{my_id}" do |msg| + MessageBus.subscribe "/server-name-reply/#{my_id}" do |msg| MessageBusDiags.seen_host(msg.data) end - DiscourseBus.subscribe "/server-name" do |msg| - DiscourseBus.publish msg.data["channel"], MessageBusDiags.my_id + MessageBus.subscribe "/server-name" do |msg| + MessageBus.publish msg.data["channel"], MessageBusDiags.my_id end @subscribed = true end diff --git a/lib/site_setting_extension.rb b/lib/site_setting_extension.rb index 22ef80961..456f94d33 100644 --- a/lib/site_setting_extension.rb +++ b/lib/site_setting_extension.rb @@ -221,7 +221,7 @@ module SiteSettingExtension def ensure_listen_for_changes unless @subscribed - DiscourseBus.subscribe("/site_settings") do |message| + MessageBus.subscribe("/site_settings") do |message| process_message(message) end @subscribed = true @@ -233,10 +233,10 @@ module SiteSettingExtension if data["process"] != process_id begin @last_message_processed = message.global_id - DiscourseBus.on_connect.call(message.site_id) + MessageBus.on_connect.call(message.site_id) refresh! ensure - DiscourseBus.on_disconnect.call(message.site_id) + MessageBus.on_disconnect.call(message.site_id) end end end @@ -294,7 +294,7 @@ module SiteSettingExtension end def notify_changed! - DiscourseBus.publish('/site_settings', {process: process_id}) + MessageBus.publish('/site_settings', {process: process_id}) end def has_setting?(name) diff --git a/plugins/poll/plugin.rb b/plugins/poll/plugin.rb index c66e3cc7d..853e39cde 100644 --- a/plugins/poll/plugin.rb +++ b/plugins/poll/plugin.rb @@ -70,7 +70,7 @@ after_initialize do post.custom_fields["#{VOTES_CUSTOM_FIELD}-#{user_id}"] = votes post.save_custom_fields(true) - DiscourseBus.publish("/polls/#{post_id}", { polls: polls }) + MessageBus.publish("/polls/#{post_id}", { polls: polls }) return [poll, options] end @@ -100,7 +100,7 @@ after_initialize do post.save_custom_fields(true) - DiscourseBus.publish("/polls/#{post_id}", { polls: polls }) + MessageBus.publish("/polls/#{post_id}", { polls: polls }) polls[poll_name] end @@ -299,7 +299,7 @@ after_initialize do post.save_custom_fields(true) # publish the changes - DiscourseBus.publish("/polls/#{post.id}", { polls: polls }) + MessageBus.publish("/polls/#{post.id}", { polls: polls }) end end else @@ -321,7 +321,7 @@ after_initialize do # tells the front-end we have a poll for that post on(:post_created) do |post| next if post.is_first_post? || post.custom_fields[POLLS_CUSTOM_FIELD].blank? - DiscourseBus.publish("/polls", { post_id: post.id }) + MessageBus.publish("/polls", { post_id: post.id }) end add_to_serializer(:post, :polls, false) { post_custom_fields[POLLS_CUSTOM_FIELD] } diff --git a/plugins/poll/spec/controllers/polls_controller_spec.rb b/plugins/poll/spec/controllers/polls_controller_spec.rb index 3e79ab7cd..ab9081285 100644 --- a/plugins/poll/spec/controllers/polls_controller_spec.rb +++ b/plugins/poll/spec/controllers/polls_controller_spec.rb @@ -10,7 +10,7 @@ describe ::DiscoursePoll::PollsController do describe "#vote" do it "works" do - DiscourseBus.expects(:publish) + MessageBus.expects(:publish) xhr :put, :vote, { post_id: poll.id, poll_name: "poll", options: ["5c24fc1df56d764b550ceae1b9319125"] } @@ -84,7 +84,7 @@ describe ::DiscoursePoll::PollsController do describe "#toggle_status" do it "works for OP" do - DiscourseBus.expects(:publish) + MessageBus.expects(:publish) xhr :put, :toggle_status, { post_id: poll.id, poll_name: "poll", status: "closed" } expect(response).to be_success @@ -94,7 +94,7 @@ describe ::DiscoursePoll::PollsController do it "works for staff" do log_in(:moderator) - DiscourseBus.expects(:publish) + MessageBus.expects(:publish) xhr :put, :toggle_status, { post_id: poll.id, poll_name: "poll", status: "closed" } expect(response).to be_success diff --git a/spec/components/discourse_spec.rb b/spec/components/discourse_spec.rb index 45685d92e..5765a6d42 100644 --- a/spec/components/discourse_spec.rb +++ b/spec/components/discourse_spec.rb @@ -89,7 +89,7 @@ describe Discourse do it "adds a key in redis and publish a message through the message bus" do $redis.expects(:set).with(Discourse.readonly_mode_key, 1) - DiscourseBus.expects(:publish).with(Discourse.readonly_channel, true) + MessageBus.expects(:publish).with(Discourse.readonly_channel, true) Discourse.enable_readonly_mode end @@ -99,7 +99,7 @@ describe Discourse do it "removes a key from redis and publish a message through the message bus" do $redis.expects(:del).with(Discourse.readonly_mode_key) - DiscourseBus.expects(:publish).with(Discourse.readonly_channel, false) + MessageBus.expects(:publish).with(Discourse.readonly_channel, false) Discourse.disable_readonly_mode end diff --git a/spec/components/post_creator_spec.rb b/spec/components/post_creator_spec.rb index c356a4331..411e8d715 100644 --- a/spec/components/post_creator_spec.rb +++ b/spec/components/post_creator_spec.rb @@ -72,7 +72,7 @@ describe PostCreator do it "does not notify on system messages" do admin = Fabricate(:admin) - messages = DiscourseBus.track_publish do + messages = MessageBus.track_publish do p = PostCreator.create(admin, basic_topic_params.merge(post_type: Post.types[:moderator_action])) PostCreator.create(admin, basic_topic_params.merge(topic_id: p.topic_id, post_type: Post.types[:moderator_action])) end @@ -93,7 +93,7 @@ describe PostCreator do created_post = nil reply = nil - messages = DiscourseBus.track_publish do + messages = MessageBus.track_publish do created_post = PostCreator.new(admin, basic_topic_params.merge(category: cat.id)).create reply = PostCreator.new(admin, raw: "this is my test reply 123 testing", topic_id: created_post.topic_id).create end @@ -118,7 +118,7 @@ describe PostCreator do it 'generates the correct messages for a normal topic' do p = nil - messages = DiscourseBus.track_publish do + messages = MessageBus.track_publish do p = creator.create end diff --git a/spec/models/topic_spec.rb b/spec/models/topic_spec.rb index a7ca9549d..66ce8e17b 100644 --- a/spec/models/topic_spec.rb +++ b/spec/models/topic_spec.rb @@ -573,7 +573,7 @@ describe Topic do describe "make_banner!" do it "changes the topic archetype to 'banner'" do - messages = DiscourseBus.track_publish do + messages = MessageBus.track_publish do topic.make_banner!(user) expect(topic.archetype).to eq(Archetype.banner) end @@ -597,7 +597,7 @@ describe Topic do it "resets the topic archetype" do topic.expects(:add_moderator_post) - DiscourseBus.expects(:publish).with("/site/banner", nil) + MessageBus.expects(:publish).with("/site/banner", nil) topic.remove_banner!(user) expect(topic.archetype).to eq(Archetype.default) end