Skip to content

QuestionNotifierをnewspaperからActiveSupport::Notificationsに移行#8982

Closed
smallmonkeykey wants to merge 710 commits intomainfrom
chore/replace-question_notifier
Closed

QuestionNotifierをnewspaperからActiveSupport::Notificationsに移行#8982
smallmonkeykey wants to merge 710 commits intomainfrom
chore/replace-question_notifier

Conversation

@smallmonkeykey
Copy link
Copy Markdown
Contributor

@smallmonkeykey smallmonkeykey commented Jul 24, 2025

QuestionNotifierをnewspaperからActiveSupport::Notificationsに移行しました。

Issue

概要

  • 質問を作成し公開した時のDiscord通知機能を、NewspaperからActiveSupport::Notificationsへ移行しました。
  • 開発環境では実際のDiscord送信の代わりに、log/development.logMessage to Discord. が出力される仕組みになってます。
  • 通知タイミングは以下の2パターンです:
  1. 質問を作成し登録を押した時
  2. WIP → 公開に変更した場合

変更確認方法

  1. chore/replace-question_notifierブランチをローカルに取り込む
  2. foreman start -f Procfile.devでローカルで立ち上げます
  3. 現在のターミナルとは別のターミナルを開いて、以下のコマンドを実行してください
    tail -f log/development.log | grep "Message to Discord"
    通知が飛んだ場合、Message to Discord. という出力があるかを確認できます
  4. hajime またはkimuraでログインを行います
  5. http://localhost:3000/questions/newで質問を作成します

以下の3パターンを検証してください
1:WIP保存のみ
質問をWIPで保存してください
期待結果:Message to Discord. のログが出力されないことを確認してください

2:WIP → 公開に変更
上記で作成したWIPの質問を質問を公開ボタンをクリックし公開してください
期待結果:ログに Message to Discord. が出力されることを確認してください

3:質問を作成し、登録するをクリックしてください
期待結果:ログに Message to Discord. が出力されることを確認してください

% tail -f log/development.log | grep "Message to Discord"
Message to Discord.
Message to Discord.

このような表示がされます。

Screenshot

見た目に変更はないためスクリーンショットはありません。

Summary by CodeRabbit

  • 新機能

    • 質問の作成および更新時に新しい通知イベントが追加され、リアルタイム通知が強化されました。
  • リファクタ

    • 通知の購読設定が整理され、通知処理の一貫性と拡張性が向上しました。
    • 通知ハンドラの受け取り仕様が更新され、今後の通知拡張に対応しやすくなりました。

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Jul 24, 2025

Walkthrough

QuestionsController が Newspaper.publish から ActiveSupport::Notifications.instrument へ切り替わり、QuestionNotifier のサブスクライブ先を初期化ファイルへ移動し、Notifier#call のシグネチャが ActiveSupport::Notifications のコールバック形式(5引数)に変更されました。

Changes

Cohort / File(s) 変更内容概要
Controller changes
app/controllers/questions_controller.rb
質問作成・更新時に Newspaper.publish の代わりに `ActiveSupport::Notifications.instrument('question.create'
Notifier implementation
app/models/question_notifier.rb
call(payload)call(_name, _started, _finished, _unique_id, payload) にシグネチャを変更。payload から question を取り出して既存ロジックを実行。
AS::Notifications subscriptions
config/initializers/active_support_notifications.rb
QuestionNotifierquestion.createquestion.update イベントに subscribe する登録を追加。
Newspaper initializer cleanup
config/initializers/newspaper.rb
QuestionNotifier の Newspaper ベースの購読(インスタンス化と subscribe)を削除。

Sequence Diagram(s)

sequenceDiagram
    participant Controller as QuestionsController
    participant ASNotif as ActiveSupport::Notifications
    participant Notifier as QuestionNotifier

    Controller->>ASNotif: instrument('question.create'|'question.update', question)
    ASNotif->>Notifier: call(_name, _started, _finished, _unique_id, payload)
    Note right of Notifier: payload[:question] を取得し wip チェック
    Notifier->>Notifier: 通知メッセージ生成・送信
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related issues

Possibly related PRs

Suggested reviewers

  • Miya096jp
  • komagata

Poem

🐰
質問に風が通り抜けるよ
チャイムはもう ActiveSupport で鳴る
古い新聞をそっと置いて
うさぎは耳をぴんと立てる
新しいイベントで跳ね回ろう

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/questions_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/question_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

'

config/initializers/active_support_notifications.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

'

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.


📜 Recent review details

Configuration used: .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 9df44bc and 47eb351.

📒 Files selected for processing (4)
  • app/controllers/questions_controller.rb (2 hunks)
  • app/models/question_notifier.rb (1 hunks)
  • config/initializers/active_support_notifications.rb (1 hunks)
  • config/initializers/newspaper.rb (0 hunks)
💤 Files with no reviewable changes (1)
  • config/initializers/newspaper.rb
🚧 Files skipped from review as they are similar to previous changes (3)
  • config/initializers/active_support_notifications.rb
  • app/controllers/questions_controller.rb
  • app/models/question_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
✨ 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-question_notifier

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.

Miya096jp and others added 10 commits July 24, 2025 16:03
CIでprettierのlintエラー発生のため、prettier
--write...コマンドで再試行、修正された2ファイルをcommitに含める
controllerの`render:json: @watches`を削除
コメントのMarkdown元テキストを表示するRawボタンの実装
…otifications-in-product-notifier

Product系3クラス分newspaperをActiveSupport::Notificationsに移行
…nilla_js

質問一覧・詳細表示機能の非Vue化
@smallmonkeykey smallmonkeykey marked this pull request as ready for review July 24, 2025 07:32
@smallmonkeykey smallmonkeykey marked this pull request as draft July 24, 2025 07:49
@smallmonkeykey smallmonkeykey marked this pull request as ready for review July 24, 2025 07:49
@smallmonkeykey smallmonkeykey self-assigned this Jul 24, 2025
@smallmonkeykey smallmonkeykey force-pushed the chore/replace-question_notifier branch from 243cac4 to 81e5021 Compare July 24, 2025 08:25
jun-kondo and others added 6 commits July 24, 2025 19:01
@smallmonkeykey smallmonkeykey force-pushed the chore/replace-question_notifier branch from 81e5021 to 9df44bc Compare July 24, 2025 13:23
@smallmonkeykey
Copy link
Copy Markdown
Contributor Author

@Miya096jp
ミヤさん、初めまして!リサと申します。
こちらのレビューをお願いできますでしょうか?
急ぎではないです🙏

@Miya096jp
Copy link
Copy Markdown
Contributor

@smallmonkeykey

お疲れ様です!はじめまして!
承知しました🙆🏻‍♂️

sjabcdefin and others added 21 commits August 13, 2025 16:42
user が1箇所でしか出てこず、可読性向上のため
ヘッドレスだと失敗するテストを修正
…heck-test

ローカル環境で通らなかったテストnotify comment and checkを通るように修正
@komagata
Copy link
Copy Markdown
Member

@smallmonkeykey conflictの修正をお願いします。大変であれば新規にPRを作るのもいいと思います。

@smallmonkeykey
Copy link
Copy Markdown
Contributor Author

@komagata
ご連絡ありがとうございます🙇‍♂️
今日中に対応ができなかった場合、新しくPRを作り変えたいと思います。

@komagata
Copy link
Copy Markdown
Member

@smallmonkeykey もし不要でしたらこのブランチの削除をお願いします。(上にあるDelete branchボタンで削除できます)

@smallmonkeykey smallmonkeykey deleted the chore/replace-question_notifier branch August 26, 2025 05:43
@smallmonkeykey
Copy link
Copy Markdown
Contributor Author

@komagata
ブランチの削除を行いました!

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.