diff --git a/app/controllers/products_controller.rb b/app/controllers/products_controller.rb index b713df4da8a..12b52f8bcd4 100644 --- a/app/controllers/products_controller.rb +++ b/app/controllers/products_controller.rb @@ -65,7 +65,7 @@ def update set_wip update_published_at if @product.update(product_params) - Newspaper.publish(:product_update, { product: @product, current_user: }) + ActiveSupport::Notifications.instrument('product.update', { product: @product, current_user: }) ActiveSupport::Notifications.instrument('product.save', product: @product) notice_another_mentor_assigned_as_checker redirect_to Redirection.determin_url(self, @product), notice: notice_message(@product, :update) diff --git a/app/models/comment/after_create_callback.rb b/app/models/comment/after_create_callback.rb index 684a0981d77..858fdfa9b29 100644 --- a/app/models/comment/after_create_callback.rb +++ b/app/models/comment/after_create_callback.rb @@ -6,7 +6,7 @@ def after_commit(comment) create_watch(comment) notify_to_watching_user(comment) elsif comment.receiver.present? && comment.receiver != comment.sender - Newspaper.publish(:came_comment, { comment: }) + ActiveSupport::Notifications.instrument('came.comment', comment:) end if comment.commentable.instance_of?(Talk) diff --git a/app/models/comment_notifier.rb b/app/models/comment_notifier.rb index 0521a64b523..e96480bb1fc 100644 --- a/app/models/comment_notifier.rb +++ b/app/models/comment_notifier.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true class CommentNotifier - def call(payload) + def call(_name, _started, _finished, _id, payload) comment = payload[:comment] return if comment.nil? diff --git a/app/models/product_update_notifier_for_checker.rb b/app/models/product_update_notifier_for_checker.rb index d6fbf07f82f..a02025407ad 100644 --- a/app/models/product_update_notifier_for_checker.rb +++ b/app/models/product_update_notifier_for_checker.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true class ProductUpdateNotifierForChecker - def call(payload) + def call(_name, _started, _finished, _id, payload) product = payload[:product] current_user = payload[:current_user] return if product.wip? || product.checker_id.nil? || !current_user.nil? && current_user.admin_or_mentor? diff --git a/app/models/product_update_notifier_for_watcher.rb b/app/models/product_update_notifier_for_watcher.rb index ba7424d1e68..e702ce5f1c1 100644 --- a/app/models/product_update_notifier_for_watcher.rb +++ b/app/models/product_update_notifier_for_watcher.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true class ProductUpdateNotifierForWatcher - def call(payload) + def call(_name, _started, _finished, _id, payload) product = payload[:product] current_user = payload[:current_user] return if product.wip? || product.watches.nil? || !current_user.nil? && current_user.admin_or_mentor? diff --git a/config/initializers/active_support_notifications.rb b/config/initializers/active_support_notifications.rb index d9d33711181..d30c33a22ce 100644 --- a/config/initializers/active_support_notifications.rb +++ b/config/initializers/active_support_notifications.rb @@ -27,7 +27,10 @@ ActiveSupport::Notifications.subscribe('came.inquiry', InquiryNotifier.new) ActiveSupport::Notifications.subscribe('regular_event.update', RegularEventUpdateNotifier.new) ActiveSupport::Notifications.subscribe('student_or_trainee.create', TimesChannelCreator.new) - + ActiveSupport::Notifications.subscribe('product.update', ProductUpdateNotifierForWatcher.new) + ActiveSupport::Notifications.subscribe('product.update', ProductUpdateNotifierForChecker.new) + ActiveSupport::Notifications.subscribe('came.comment', CommentNotifier.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 56ba4e26470..d2c3d00f7a0 100644 --- a/config/initializers/newspaper.rb +++ b/config/initializers/newspaper.rb @@ -30,8 +30,5 @@ Newspaper.subscribe(:question_create, question_notifier) Newspaper.subscribe(:question_update, question_notifier) - Newspaper.subscribe(:product_update, ProductUpdateNotifierForWatcher.new) - Newspaper.subscribe(:product_update, ProductUpdateNotifierForChecker.new) - Newspaper.subscribe(:came_comment, CommentNotifier.new) Newspaper.subscribe(:came_comment_in_talk, CommentNotifierForAdmin.new) end diff --git a/test/models/product_update_notifier_for_checker_test.rb b/test/models/product_update_notifier_for_checker_test.rb index a17459d031c..ba032540793 100644 --- a/test/models/product_update_notifier_for_checker_test.rb +++ b/test/models/product_update_notifier_for_checker_test.rb @@ -15,7 +15,7 @@ class ProductUpdateNotifierForCheckerTest < ActiveSupport::TestCase product.save! assert_difference -> { AbstractNotifier::Testing::Driver.enqueued_deliveries.count }, 1 do - ProductUpdateNotifierForChecker.new.call({ product:, current_user: product.user }) + ProductUpdateNotifierForChecker.new.call(nil, nil, nil, nil, { product:, current_user: product.user }) end end @@ -30,7 +30,7 @@ class ProductUpdateNotifierForCheckerTest < ActiveSupport::TestCase product.save! assert_difference -> { AbstractNotifier::Testing::Driver.enqueued_deliveries.count }, 0 do - ProductUpdateNotifierForChecker.new.call({ product:, current_user: product.user }) + ProductUpdateNotifierForChecker.new.call(nil, nil, nil, nil, { product:, current_user: product.user }) end end @@ -44,7 +44,7 @@ class ProductUpdateNotifierForCheckerTest < ActiveSupport::TestCase product.save! assert_difference -> { AbstractNotifier::Testing::Driver.enqueued_deliveries.count }, 0 do - ProductUpdateNotifierForChecker.new.call({ product:, current_user: product.user }) + ProductUpdateNotifierForChecker.new.call(nil, nil, nil, nil, { product:, current_user: product.user }) end end @@ -58,7 +58,7 @@ class ProductUpdateNotifierForCheckerTest < ActiveSupport::TestCase product.save! assert_difference -> { AbstractNotifier::Testing::Driver.enqueued_deliveries.count }, 0 do - ProductUpdateNotifierForChecker.new.call({ product:, current_user: users(:mentormentaro) }) + ProductUpdateNotifierForChecker.new.call(nil, nil, nil, nil, { product:, current_user: users(:mentormentaro) }) end end end diff --git a/test/models/product_update_notifier_for_watcher_test.rb b/test/models/product_update_notifier_for_watcher_test.rb index 10c7d938cf9..4905e079dac 100644 --- a/test/models/product_update_notifier_for_watcher_test.rb +++ b/test/models/product_update_notifier_for_watcher_test.rb @@ -10,7 +10,7 @@ class ProductUpdateNotifierForWatcherTest < ActiveSupport::TestCase product = products(:product6) assert_difference -> { AbstractNotifier::Testing::Driver.enqueued_deliveries.count }, 1 do - ProductUpdateNotifierForWatcher.new.call({ product:, current_user: product.user }) + ProductUpdateNotifierForWatcher.new.call(nil, nil, nil, nil, { product:, current_user: product.user }) end end @@ -19,7 +19,7 @@ class ProductUpdateNotifierForWatcherTest < ActiveSupport::TestCase product = products(:product5) assert_difference -> { AbstractNotifier::Testing::Driver.enqueued_deliveries.count }, 0 do - ProductUpdateNotifierForWatcher.new.call({ product:, current_user: product.user }) + ProductUpdateNotifierForWatcher.new.call(nil, nil, nil, nil, { product:, current_user: product.user }) end end @@ -28,7 +28,7 @@ class ProductUpdateNotifierForWatcherTest < ActiveSupport::TestCase product = products(:product73) assert_difference -> { AbstractNotifier::Testing::Driver.enqueued_deliveries.count }, 0 do - ProductUpdateNotifierForWatcher.new.call({ product:, current_user: product.user }) + ProductUpdateNotifierForWatcher.new.call(nil, nil, nil, nil, { product:, current_user: product.user }) end end @@ -37,7 +37,7 @@ class ProductUpdateNotifierForWatcherTest < ActiveSupport::TestCase product = products(:product6) assert_difference -> { AbstractNotifier::Testing::Driver.enqueued_deliveries.count }, 0 do - ProductUpdateNotifierForWatcher.new.call({ product:, current_user: users(:mentormentaro) }) + ProductUpdateNotifierForWatcher.new.call(nil, nil, nil, nil, { product:, current_user: users(:mentormentaro) }) end end end