Skip to content

ProductUpdateNotifier、CommentNotifierをNewspaperからActiveSupport::Notificationsに移行#8970

Merged
komagata merged 4 commits intomainfrom
chore/replace-newspaper-with-activesupport-nofitications-for-product-and-comment
Aug 25, 2025
Merged

ProductUpdateNotifier、CommentNotifierをNewspaperからActiveSupport::Notificationsに移行#8970
komagata merged 4 commits intomainfrom
chore/replace-newspaper-with-activesupport-nofitications-for-product-and-comment

Conversation

@matuaya
Copy link
Copy Markdown
Contributor

@matuaya matuaya commented Jul 20, 2025

Issue

概要

ProductUpdateNotifierForWatcher、ProductUpdateNotifierForChecker、CommentNotifierをNewspaperからActiveSupport::Notificationsのsubscribeの仕組みに移行しました。

AnswererWatcherをnewspaperからActiveSupport::Notificationsに移行のPRを参考にしました。

変更確認方法

  1. ブランチchore/replace-newspaper-with-activesupport-nofitications-for-product-and-commentをローカルに取り込む

  2. UIでの確認

  • 相談室でAdminがコメントした際、相談者に通知メールが送られることを確認。
スクリーンショット 2025-07-28 6 09 54
  • 提出物を更新した際に、担当しているメンターとwatchしている人に通知メールが送られることを確認。
    *メールは http://localhost:3000/letter_opener/ で確認

Screenshot

UIに変化がなかったためスクリーンショットは省略しています。

Summary by CodeRabbit

  • 新機能

    • 製品更新とコメント受信の通知ルートが新しいイベント仕組みへ移行され、通知配信が統一されました。
  • リファクタ

    • 通知処理を標準的なイベント基盤に移行して管理を簡素化しました。
    • 通知ハンドラの受け取り引数が変更され、将来の拡張に備えた互換性対応が行われました。
  • テスト

    • テスト呼び出しを新しいハンドラ仕様に合わせて更新しました。

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Jul 20, 2025

Walkthrough

この変更は、カスタムイベント通知システム「Newspaper」からRails標準の「ActiveSupport::Notifications」への移行を行っています。プロダクト更新およびコメント作成のイベント発行を文字列イベント名のinstrument呼び出しへ置換し、購読者のコールシグネチャをActiveSupport::Notificationsの5引数形式に合わせ、購読登録をinitializersへ移動しています。

Changes

Cohort / File(s) Change Summary
ProductsController変更
app/controllers/products_controller.rb
Newspaper.publish(:product_update, product: ..., current_user: ...)ActiveSupport::Notifications.instrument('product.update', product: ..., current_user: ...) に置換。
Comment after_create callback
app/models/comment/after_create_callback.rb
Newspaper.publish(:came_comment, comment: ...)ActiveSupport::Notifications.instrument('came.comment', comment:) に置換(キーワード引数で渡す)。
Notifierクラスのシグネチャ変更
app/models/comment_notifier.rb, app/models/product_update_notifier_for_checker.rb, app/models/product_update_notifier_for_watcher.rb
def call(payload)def call(_name, _started, _finished, _id, payload) に変更。内部ロジックは従来どおりで追加引数は未使用(先頭にアンダースコア)。
ActiveSupport購読登録追加
config/initializers/active_support_notifications.rb
'product.update'ProductUpdateNotifierForWatcherProductUpdateNotifierForChecker'came.comment'CommentNotifier の新規購読を追加。
Newspaper購読削除
config/initializers/newspaper.rb
:product_update および :came_comment に対する Newspaper の購読登録を削除(他の購読は維持)。
テスト呼び出し更新(checker)
test/models/product_update_notifier_for_checker_test.rb
テスト内の call 呼び出しを新シグネチャに合わせ、先頭に4つの nil を追加してペイロードを渡すよう変更。
テスト呼び出し更新(watcher)
test/models/product_update_notifier_for_watcher_test.rb
同上:call 呼び出しを先頭に4つの nil を追加してペイロードを渡すよう変更。

Sequence Diagram(s)

sequenceDiagram
    participant Controller as ProductsController
    participant ASN as ActiveSupport::Notifications
    participant Watcher as ProductUpdateNotifierForWatcher
    participant Checker as ProductUpdateNotifierForChecker

    Controller->>ASN: instrument('product.update', product:..., current_user:...)
    ASN->>Watcher: call(_name, _started, _finished, _id, payload)
    ASN->>Checker: call(_name, _started, _finished, _id, payload)
Loading
sequenceDiagram
    participant Callback as Comment::AfterCreateCallback
    participant ASN as ActiveSupport::Notifications
    participant Notifier as CommentNotifier

    Callback->>ASN: instrument('came.comment', comment: comment)
    ASN->>Notifier: call(_name, _started, _finished, _id, payload)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~15–20 minutes

Possibly related issues

Possibly related PRs

Suggested reviewers

  • jun-kondo
  • komagata

Poem

うさぎが跳ねて知らせるよ、
古い新聞は置き去りに、通知の風が通る、
ぴょんとinstrument、payloadを運んで、
サブスクライブの耳がピンと立つ、
ちいさな変更で春が来たよ 🐇✨

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 RuboCop (1.76.1)
app/controllers/products_controller.rb

rubocop-minitest extension supports plugin, specify plugins: rubocop-minitest instead of require: rubocop-minitest in /.rubocop.yml.
For more information, see https://docs.rubocop.org/rubocop/plugin_migration_guide.html.
rubocop-capybara extension supports plugin, specify plugins: rubocop-capybara instead of require: rubocop-capybara in /.rubocop.yml.
For more information, see https://docs.rubocop.org/rubocop/plugin_migration_guide.html.
Unable to find gem rubocop-fjord; is the gem installed? Gem::MissingSpecError
/var/lib/gems/3.1.0/gems/rubocop-1.79.2/lib/rubocop/config_loader_resolver.rb:309:in rescue in gem_config_path' /var/lib/gems/3.1.0/gems/rubocop-1.79.2/lib/rubocop/config_loader_resolver.rb:293:in gem_config_path'
/var/lib/gems/3.1.0/gems/rubocop-1.79.2/lib/rubocop/config_loader_resolver.rb:84:in block (2 levels) in resolve_inheritance_from_gems' /var/lib/gems/3.1.0/gems/rubocop-1.79.2/lib/rubocop/config_loader_resolver.rb:82:in reverse_each'
/var/lib/gems/3.1.0/gems/rubocop-1.79.2/lib/rubocop/config_loader_resolver.rb:82:in block in resolve_inheritance_from_gems' /var/lib/gems/3.1.0/gems/rubocop-1.79.2/lib/rubocop/config_loader_resolver.rb:76:in each_pair'
/var/lib/gems/3.1.0/gems/rubocop-1.79.2/lib/rubocop/config_loader_resolver.rb:76:in resolve_inheritance_from_gems' /var/lib/gems/3.1.0/gems/rubocop-1.79.2/lib/rubocop/config_loader.rb:58:in load_file'
/var/lib/gems/3.1.0/gems/rubocop-1.79.2/lib/rubocop/config_store.rb:29:in options_config=' /var/lib/gems/3.1.0/gems/rubocop-1.79.2/lib/rubocop/cli.rb:162:in act_on_options'
/var/lib/gems/3.1.0/gems/rubocop-1.79.2/lib/rubocop/cli.rb:47:in block in run' /var/lib/gems/3.1.0/gems/rubocop-1.79.2/lib/rubocop/cli.rb:82:in profile_if_needed'
/var/lib/gems/3.1.0/gems/rubocop-1.79.2/lib/rubocop/cli.rb:43:in run' /var/lib/gems/3.1.0/gems/rubocop-1.79.2/exe/rubocop:19:in <top (required)>'
/usr/local/bin/rubocop:25:in load' /usr/local/bin/rubocop:25:in

'

app/models/comment/after_create_callback.rb

rubocop-minitest extension supports plugin, specify plugins: rubocop-minitest instead of require: rubocop-minitest in /.rubocop.yml.
For more information, see https://docs.rubocop.org/rubocop/plugin_migration_guide.html.
rubocop-capybara extension supports plugin, specify plugins: rubocop-capybara instead of require: rubocop-capybara in /.rubocop.yml.
For more information, see https://docs.rubocop.org/rubocop/plugin_migration_guide.html.
Unable to find gem rubocop-fjord; is the gem installed? Gem::MissingSpecError
/var/lib/gems/3.1.0/gems/rubocop-1.79.2/lib/rubocop/config_loader_resolver.rb:309:in rescue in gem_config_path' /var/lib/gems/3.1.0/gems/rubocop-1.79.2/lib/rubocop/config_loader_resolver.rb:293:in gem_config_path'
/var/lib/gems/3.1.0/gems/rubocop-1.79.2/lib/rubocop/config_loader_resolver.rb:84:in block (2 levels) in resolve_inheritance_from_gems' /var/lib/gems/3.1.0/gems/rubocop-1.79.2/lib/rubocop/config_loader_resolver.rb:82:in reverse_each'
/var/lib/gems/3.1.0/gems/rubocop-1.79.2/lib/rubocop/config_loader_resolver.rb:82:in block in resolve_inheritance_from_gems' /var/lib/gems/3.1.0/gems/rubocop-1.79.2/lib/rubocop/config_loader_resolver.rb:76:in each_pair'
/var/lib/gems/3.1.0/gems/rubocop-1.79.2/lib/rubocop/config_loader_resolver.rb:76:in resolve_inheritance_from_gems' /var/lib/gems/3.1.0/gems/rubocop-1.79.2/lib/rubocop/config_loader.rb:58:in load_file'
/var/lib/gems/3.1.0/gems/rubocop-1.79.2/lib/rubocop/config_store.rb:29:in options_config=' /var/lib/gems/3.1.0/gems/rubocop-1.79.2/lib/rubocop/cli.rb:162:in act_on_options'
/var/lib/gems/3.1.0/gems/rubocop-1.79.2/lib/rubocop/cli.rb:47:in block in run' /var/lib/gems/3.1.0/gems/rubocop-1.79.2/lib/rubocop/cli.rb:82:in profile_if_needed'
/var/lib/gems/3.1.0/gems/rubocop-1.79.2/lib/rubocop/cli.rb:43:in run' /var/lib/gems/3.1.0/gems/rubocop-1.79.2/exe/rubocop:19:in <top (required)>'
/usr/local/bin/rubocop:25:in load' /usr/local/bin/rubocop:25:in

'

app/models/comment_notifier.rb

rubocop-minitest extension supports plugin, specify plugins: rubocop-minitest instead of require: rubocop-minitest in /.rubocop.yml.
For more information, see https://docs.rubocop.org/rubocop/plugin_migration_guide.html.
rubocop-capybara extension supports plugin, specify plugins: rubocop-capybara instead of require: rubocop-capybara in /.rubocop.yml.
For more information, see https://docs.rubocop.org/rubocop/plugin_migration_guide.html.
Unable to find gem rubocop-fjord; is the gem installed? Gem::MissingSpecError
/var/lib/gems/3.1.0/gems/rubocop-1.79.2/lib/rubocop/config_loader_resolver.rb:309:in rescue in gem_config_path' /var/lib/gems/3.1.0/gems/rubocop-1.79.2/lib/rubocop/config_loader_resolver.rb:293:in gem_config_path'
/var/lib/gems/3.1.0/gems/rubocop-1.79.2/lib/rubocop/config_loader_resolver.rb:84:in block (2 levels) in resolve_inheritance_from_gems' /var/lib/gems/3.1.0/gems/rubocop-1.79.2/lib/rubocop/config_loader_resolver.rb:82:in reverse_each'
/var/lib/gems/3.1.0/gems/rubocop-1.79.2/lib/rubocop/config_loader_resolver.rb:82:in block in resolve_inheritance_from_gems' /var/lib/gems/3.1.0/gems/rubocop-1.79.2/lib/rubocop/config_loader_resolver.rb:76:in each_pair'
/var/lib/gems/3.1.0/gems/rubocop-1.79.2/lib/rubocop/config_loader_resolver.rb:76:in resolve_inheritance_from_gems' /var/lib/gems/3.1.0/gems/rubocop-1.79.2/lib/rubocop/config_loader.rb:58:in load_file'
/var/lib/gems/3.1.0/gems/rubocop-1.79.2/lib/rubocop/config_store.rb:29:in options_config=' /var/lib/gems/3.1.0/gems/rubocop-1.79.2/lib/rubocop/cli.rb:162:in act_on_options'
/var/lib/gems/3.1.0/gems/rubocop-1.79.2/lib/rubocop/cli.rb:47:in block in run' /var/lib/gems/3.1.0/gems/rubocop-1.79.2/lib/rubocop/cli.rb:82:in profile_if_needed'
/var/lib/gems/3.1.0/gems/rubocop-1.79.2/lib/rubocop/cli.rb:43:in run' /var/lib/gems/3.1.0/gems/rubocop-1.79.2/exe/rubocop:19:in <top (required)>'
/usr/local/bin/rubocop:25:in load' /usr/local/bin/rubocop:25:in

'

  • 2 others

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch chore/replace-newspaper-with-activesupport-nofitications-for-product-and-comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@matuaya matuaya force-pushed the chore/replace-newspaper-with-activesupport-nofitications-for-product-and-comment branch from ea4323e to d211703 Compare July 27, 2025 21:02
@matuaya matuaya marked this pull request as ready for review July 27, 2025 21:17
@github-actions github-actions bot requested a review from komagata July 27, 2025 21:17
@matuaya matuaya force-pushed the chore/replace-newspaper-with-activesupport-nofitications-for-product-and-comment branch 3 times, most recently from a8b05d9 to 6373216 Compare July 30, 2025 07:28
@matuaya matuaya force-pushed the chore/replace-newspaper-with-activesupport-nofitications-for-product-and-comment branch 2 times, most recently from 98a7976 to 0523d50 Compare August 6, 2025 18:13
@matuaya
Copy link
Copy Markdown
Contributor Author

matuaya commented Aug 7, 2025

@jun-kondo
もしお時間がありましたらレビューお願いできますでしょうか?🙇‍♀️

@matuaya matuaya requested a review from jun-kondo August 7, 2025 07:47
@jun-kondo
Copy link
Copy Markdown
Contributor

@matuaya
承知しましたー
確認しますので、少々お時間くださいー🙏

@matuaya
Copy link
Copy Markdown
Contributor Author

matuaya commented Aug 8, 2025

@jun-kondo
ありがとうございます!😊

Copy link
Copy Markdown
Contributor

@jun-kondo jun-kondo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@matuaya
お疲れ様です🍵動作確認出来ました。
コードの方も問題ありませんので、Approve致しますー

後は下記ご対応をお願いします👀

  • プルリクエストのタイトルをブランチ名からわかりやすいものに変更
  • プルリクエストのAssigneesに自身を設定

よろしくお願い致します🙇‍♂️

@matuaya matuaya self-assigned this Aug 10, 2025
@matuaya matuaya changed the title Chore/replace newspaper with activesupport nofitications for product and comment ProductUpdateNotifier、CommentNotifierをNewspaperからActiveSupport::Notificationsに移行 Aug 10, 2025
@matuaya
Copy link
Copy Markdown
Contributor Author

matuaya commented Aug 10, 2025

@jun-kondo
レビューとご指摘いただきありがとうございました🙇‍♀️
大変助かりました!

@komagata
メンバーレビューが完了しましたので確認お願いいたします🙇‍♀️

Copy link
Copy Markdown
Member

@komagata komagata left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

確認させて頂きました。OKです〜🙆‍♂️

@komagata
Copy link
Copy Markdown
Member

📝 リリース直前なので、このリリースが終わり次第mainにマージしたいと思います。

@komagata
Copy link
Copy Markdown
Member

@matuaya リリースにあたってmainとproductionが変わった結果conflictが増えてしまっています、すみません。
conflictの修正をお願いできればありがたいです。

@komagata
Copy link
Copy Markdown
Member

📝 下記でmainの最新が取り込めると思います。

$ git checkout main
$ git pull origin main
$ git checkout chore/replace-newspaper-with-activesupport-nofitications-for-product-and-comment
$ git pull chore/replace-newspaper-with-activesupport-nofitications-for-product-and-comment

@matuaya matuaya force-pushed the chore/replace-newspaper-with-activesupport-nofitications-for-product-and-comment branch from 0523d50 to 12075b4 Compare August 23, 2025 09:36
Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (6)
app/models/comment_notifier.rb (3)

12-12: 文言はI18nに退避して再利用・翻訳容易性を確保

ハードコードされた日本語メッセージをI18n化すると他画面・通知との一貫性が高まります。

提案差分:

-      message: "相談部屋で#{comment.sender.login_name}さんからコメントがありました。",
+      message: I18n.t('comment_notifier.came_comment.message', sender: comment.sender.login_name),

合わせて、例えば以下をconfig/locales/comment_notifier.ja.ymlに追加してください:

ja:
  comment_notifier:
    came_comment:
      message: "相談部屋で%{sender}さんからコメントがありました。"

5-7: 異常系の可観測性を少し上げる(任意)

payload[:comment]が欠落した場合にログを1行出すと原因追跡が容易になります。

提案差分:

-    return if comment.nil?
+    if comment.nil?
+      Rails.logger.warn('[CommentNotifier] payload without :comment; skip')
+      return
+    end

8-14: アンカーはルーティングヘルパのanchor:オプションで付与して安全に結合しましょう

既存の config/environments/* では全ての環境(development, test, production)で
config.action_mailer.default_url_options が設定されているため、
メール内で絶対 URL を組み立てる場合は polymorphic_url の利用が可能です。

• 修正対象

  • ファイル:app/models/comment_notifier.rb
  • 対象行:リンク生成部(8–14行目付近)

• 提案差分

-    commentable_path = Rails.application.routes.url_helpers.polymorphic_path(comment.commentable)
-    ActivityDelivery.with(
-      comment:,
-      receiver: comment.receiver,
-      message: "相談部屋で#{comment.sender.login_name}さんからコメントがありました。",
-      link: "#{commentable_path}#latest-comment"
-    ).notify(:came_comment)
+    # アンカーはルーティングヘルパのanchorオプションで付与する
+    ActivityDelivery.with(
+      comment:,
+      receiver: comment.receiver,
+      message: "相談部屋で#{comment.sender.login_name}さんからコメントがありました。",
+      link: Rails.application.routes.url_helpers.polymorphic_url(
+        comment.commentable,
+        anchor: 'latest-comment'
+      )
+    ).notify(:came_comment)

• 補足

  • 絶対 URL が不要であれば polymorphic_path(..., anchor: 'latest-comment') を利用してください
  • メール本文で絶対 URL が必要な場合は polymorphic_url のまま、もしくは default_url_options[:host] の設定を再度ご確認ください
app/models/product_update_notifier_for_watcher.rb (3)

7-7: nilチェックの簡素化と可読性向上(安全ナビゲーション演算子)

!current_user.nil? && current_user.admin_or_mentor?current_user&.admin_or_mentor? に置換可能です。演算子優先順位の読み違いリスクも下がります。なお、product.watches.nil? は関連が常にCollectionProxyを返す想定なら常にfalseになりうるため、将来的には削除検討もありです。

-    return if product.wip? || product.watches.nil? || !current_user.nil? && current_user.admin_or_mentor?
+    return if product.wip? || product.watches.nil? || current_user&.admin_or_mentor?

9-11: 重複除去と早期returnで無駄な処理を回避

  • 二重watchレコードが存在した場合の重複通知を避けるため、SQLレベルで distinct を付与。
  • 宛先が空のときは User の問い合わせや配送処理に進まず早期return。
-    receiver_ids = product.watches.where.not(user_id: product.user_id).pluck(:user_id)
+    receiver_ids = product.watches.where.not(user_id: product.user_id).distinct.pluck(:user_id)
+    return if receiver_ids.empty?

20-22: 大量宛先時のメモリフットプリント削減(find_each)

receivers はRelationなので find_each によりバッチ処理できます。大量ユーザーでも一括ロードを避けられます。

-    receivers.each do |receiver|
+    receivers.find_each do |receiver|
       ActivityDelivery.with(product:, receiver:).notify(:product_update)
     end
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 0523d50 and 12075b4.

📒 Files selected for processing (5)
  • app/controllers/products_controller.rb (1 hunks)
  • app/models/comment/after_create_callback.rb (1 hunks)
  • app/models/comment_notifier.rb (1 hunks)
  • app/models/product_update_notifier_for_checker.rb (1 hunks)
  • app/models/product_update_notifier_for_watcher.rb (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • app/models/product_update_notifier_for_checker.rb
  • app/models/comment/after_create_callback.rb
  • app/controllers/products_controller.rb
🧰 Additional context used
📓 Path-based instructions (1)
**/*.rb

⚙️ CodeRabbit configuration file

**/*.rb: # refactoring

  • まずFat Controllerを避け、次にFat Modelを避ける。
  • Serviceクラスの乱用を避ける。
  • controller concernを作ろうとしたらPORO(Plain Old Ruby Object)やActiveRecordモデルでの実装で代替できないか検討する。

Rails Patterns

  • ViewHelperにメソッドを実装する時にはまずDecoratorパターンを使うことを検討する。(active_decorator gemを導入しているのでそれを使う)
  • 複雑なActiveRecordクエリがあり、再利用できそうな場合はQueryObjectパターンを検討する。(rails-patterns gemを導入しているのでそれのQuery機能を使う)
  • Viewにpartialを作る場合はViewComponentを使うことを検討する。
  • 複数のActiveRecordモデルを操作する1つの責務がある時や外部APIとやりとりする処理がある場合にはInteractorオブジェクトパターンを検討する。(interactor gemを導入しているのでそれを使う)
  • 複数のInteractorを実行するような処理がある場合Organizerオブジェクトパターンを検討する。(interactor gemを導入しており、その中にOrganizerの機能があるので使う)

Files:

  • app/models/product_update_notifier_for_watcher.rb
  • app/models/comment_notifier.rb
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build_and_test
🔇 Additional comments (5)
app/models/comment_notifier.rb (2)

4-4: ActiveSupport::Notificationsの5引数シグネチャ対応は問題なし

ブロック引数を使わないことを明示するための先頭アンダースコアも適切です。移行としてはLGTMです。


4-4: initializerでのsubscribeはインスタンス渡しになっており問題ありません

config/initializers/active_support_notifications.rb の32行目で以下のように書かれており、インスタンスを直接渡す形式になっています。

  • ActiveSupport::Notifications.subscribe('came.comment', CommentNotifier.new)

よって、CommentNotifier#call は意図どおりインスタンスに対して呼び出され、動作上の問題はありません。

app/models/product_update_notifier_for_watcher.rb (3)

4-4: AS::Notificationsの5引数コールシグネチャ対応は妥当です

未使用引数を先頭アンダースコアで明示しており読みやすいです。PR目的にも合致しています。


11-15: トランザクション境界の確認(送信タイミングの安定化)

通知はDBコミット後(after_*_commit)に発火していると失敗時のダングリング通知を避けられます。instrument発火位置がコミット後かを確認してください。

上の確認スクリプトの「after_commit確認」節で、ActiveSupport::Notifications.instrument("product.update", ...)after_update_commitafter_commit の中から呼ばれているかを確認できます。必要なら発火箇所を *_commit 系コールバックへ移動しましょう。


4-5: subscribe側のイベント名とpayloadキーは整合しています

  • config/initializers/active_support_notifications.rb:30 で
    ActiveSupport::Notifications.subscribe('product.update', ProductUpdateNotifierForWatcher.new) が定義されており
  • app/controllers/products_controller.rb:68 で
    ActiveSupport::Notifications.instrument('product.update', { product: @product, current_user: }) として発行されているため

イベント名とpayloadキー(:product, :current_user)が一致していることを確認しました。対応不要です。

@matuaya
Copy link
Copy Markdown
Contributor Author

matuaya commented Aug 25, 2025

@komagata
conflictを解消しましたので確認お願いいたします🙇‍♀️

Copy link
Copy Markdown
Member

@komagata komagata left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

確認させて頂きました。OKです〜🙆‍♂️

@komagata komagata merged commit 2c9b748 into main Aug 25, 2025
7 checks passed
@komagata komagata deleted the chore/replace-newspaper-with-activesupport-nofitications-for-product-and-comment branch August 25, 2025 20:17
@github-actions github-actions bot mentioned this pull request Aug 25, 2025
24 tasks
@machida
Copy link
Copy Markdown
Member

machida commented Oct 7, 2025

@matuaya こちら本番で通知が来ているのを確認してますー👍無事に通知が飛んでました✨

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants