diff --git a/app/controllers/api/correct_answers_controller.rb b/app/controllers/api/correct_answers_controller.rb index ff2ff909a90..1b356279b83 100644 --- a/app/controllers/api/correct_answers_controller.rb +++ b/app/controllers/api/correct_answers_controller.rb @@ -8,7 +8,7 @@ def create @answer.type = 'CorrectAnswer' if @answer.save Newspaper.publish(:answer_save, { answer: @answer }) - Newspaper.publish(:correct_answer_save, { answer: @answer }) + ActiveSupport::Notifications.instrument('correct_answer.save', answer: @answer) head :ok else head :bad_request diff --git a/app/controllers/comeback_controller.rb b/app/controllers/comeback_controller.rb index abf51bd5b5d..f06543cf4c3 100644 --- a/app/controllers/comeback_controller.rb +++ b/app/controllers/comeback_controller.rb @@ -12,7 +12,7 @@ def create if @user if @user&.hibernated? @user.comeback! - Newspaper.publish(:comeback_update, { user: @user }) + ActiveSupport::Notifications.instrument('comeback.update', user: @user) @user.create_comebacked_comment redirect_to root_url, notice: '休会から復帰しました。' else diff --git a/app/controllers/graduation_controller.rb b/app/controllers/graduation_controller.rb index f2fa004c90d..8916b283644 100644 --- a/app/controllers/graduation_controller.rb +++ b/app/controllers/graduation_controller.rb @@ -9,7 +9,7 @@ class GraduationController < ApplicationController def update if @user.update(graduated_on: Date.current) Subscription.new.destroy(@user.subscription_id) if @user.subscription_id - Newspaper.publish(:graduation_update, { user: @user }) + ActiveSupport::Notifications.instrument('graduation.update', user: @user) redirect_to @redirect_url, notice: 'ユーザー情報を更新しました。' else redirect_to @redirect_url, alert: 'ユーザー情報の更新に失敗しました' diff --git a/app/models/comeback_notifier.rb b/app/models/comeback_notifier.rb index 1112ba9da18..6beefbf2f9b 100644 --- a/app/models/comeback_notifier.rb +++ b/app/models/comeback_notifier.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true class ComebackNotifier - def call(payload) + def call(_name, _started, _finished, _unique_id, payload) user = payload[:user] User.admins_and_mentors.each do |admin_or_mentor| ActivityDelivery.with(sender: user, receiver: admin_or_mentor).notify(:comebacked) diff --git a/app/models/correct_answer_notifier.rb b/app/models/correct_answer_notifier.rb index 27fd20be16a..e421b3fc5c5 100644 --- a/app/models/correct_answer_notifier.rb +++ b/app/models/correct_answer_notifier.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true class CorrectAnswerNotifier - def call(payload) + def call(_name, _started, _finished, _unique_id, payload) answer = payload[:answer] notify_correct_answer(answer) notify_to_chat(answer) diff --git a/app/models/graduation_notifier.rb b/app/models/graduation_notifier.rb index 6ee13c4eada..91ff553a82e 100644 --- a/app/models/graduation_notifier.rb +++ b/app/models/graduation_notifier.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true class GraduationNotifier - def call(payload) + def call(_name, _started, _finished, _unique_id, payload) user = payload[:user] User.mentor.each do |mentor| ActivityDelivery.with(sender: user, receiver: mentor).notify(:graduated) diff --git a/app/models/question_auto_closer.rb b/app/models/question_auto_closer.rb index c933d609230..19792cf7568 100644 --- a/app/models/question_auto_closer.rb +++ b/app/models/question_auto_closer.rb @@ -99,7 +99,7 @@ def select_as_best_answer(close_answer) def publish_events(correct_answer) Newspaper.publish(:answer_save, { answer: correct_answer }) - Newspaper.publish(:correct_answer_save, { answer: correct_answer }) + ActiveSupport::Notifications.instrument('correct_answer.save', answer: correct_answer) end end end diff --git a/config/initializers/active_support_notifications.rb b/config/initializers/active_support_notifications.rb index 78fd7f5052e..84d2951c216 100644 --- a/config/initializers/active_support_notifications.rb +++ b/config/initializers/active_support_notifications.rb @@ -4,6 +4,7 @@ ActiveSupport::Notifications.subscribe('answer.create', AnswererWatcher.new) ActiveSupport::Notifications.subscribe('answer.create', AnswerNotifier.new) ActiveSupport::Notifications.subscribe('answer.create', NotifierToWatchingUser.new) + ActiveSupport::Notifications.subscribe('correct_answer.save', CorrectAnswerNotifier.new) ActiveSupport::Notifications.subscribe('event.create', EventOrganizerWatcher.new) ActiveSupport::Notifications.subscribe('regular_event.create', RegularEventOrganizerWatcher.new) sad_streak_updater = SadStreakUpdater.new @@ -30,7 +31,9 @@ ActiveSupport::Notifications.subscribe('product.update', ProductUpdateNotifierForWatcher.new) ActiveSupport::Notifications.subscribe('product.update', ProductUpdateNotifierForChecker.new) ActiveSupport::Notifications.subscribe('came.comment', CommentNotifier.new) - + ActiveSupport::Notifications.subscribe('graduation.update', GraduationNotifier.new) + ActiveSupport::Notifications.subscribe('comeback.update', ComebackNotifier.new) + learning_status_updater = LearningStatusUpdater.new ActiveSupport::Notifications.subscribe('product.save', learning_status_updater) ActiveSupport::Notifications.subscribe('check.create', learning_status_updater) diff --git a/config/initializers/newspaper.rb b/config/initializers/newspaper.rb index 6f1afea679f..6dd95f1fb73 100644 --- a/config/initializers/newspaper.rb +++ b/config/initializers/newspaper.rb @@ -4,11 +4,6 @@ answer_cache_destroyer = AnswerCacheDestroyer.new Newspaper.subscribe(:answer_save, answer_cache_destroyer) Newspaper.subscribe(:answer_destroy, answer_cache_destroyer) - Newspaper.subscribe(:correct_answer_save, CorrectAnswerNotifier.new) - - Newspaper.subscribe(:graduation_update, GraduationNotifier.new) - - Newspaper.subscribe(:comeback_update, ComebackNotifier.new) unfinished_data_destroyer = UnfinishedDataDestroyer.new Newspaper.subscribe(:retirement_create, unfinished_data_destroyer)