Skip to content

PageNotifierのPub/Sub実装をnewspaperからnotificationsに置き換え#8988

Merged
komagata merged 1 commit intomainfrom
chore/replace_newspaper_to_notifications_in_page_notifier
Jul 29, 2025
Merged

PageNotifierのPub/Sub実装をnewspaperからnotificationsに置き換え#8988
komagata merged 1 commit intomainfrom
chore/replace_newspaper_to_notifications_in_page_notifier

Conversation

@Miya096jp
Copy link
Copy Markdown
Contributor

@Miya096jp Miya096jp commented Jul 26, 2025

Issue

概要

  • Docs作成時の通知機能をnewspaperからActiveSupport::Notificationsに変更しました

  • 新規にDocsを作成・公開し、管理者とメンターに次の3種類の通知が送信されるかを確認してください。

    • メール
    • サイト内通知
    • Discord通知

補足

IssueではAnswerCacheDestroyerとPageNotifierの2つを置換するとなってますが、AnswerCacheDestroyerについては実装の不備があり別Issueで対応することになったため、動作確認はありません。


変更確認方法

chore/replace_newspaper_to_notifications_in_page_notifierをローカルに取り込む

git fetch origin chore/replace_newspaper_to_notifications_in_page_notifier
git checkout chore/replace_newspaper_to_notifications_in_page_notifier

Discord通知の確認について

Discord通知については、開発環境では通知を飛ばす代わりにRails.loggerでログを出力するようになっています

ログの確認には、現在のターミナルとは別のターミナルを開いて、以下のコマンドを実行してください

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

通知が飛んだ場合、Message to Discord.という出力があるかをターミナルで確認できます


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


パターン1. Docsを作成し即公開するパターン

  1. 受講生としてログインし、Docsを作成
  2. letter_opener の左ペインの送信先を見て、管理者とメンターのアドレスに送信されたか確認
  3. 管理者・メンターでログインし、画面右上のサイト内通知が届いているかを確認
  4. Discord通知のログを確認

パターン2. Docsを一旦WIPに保存し、その後公開するパターン

  1. 受講生としてログインし、DocsをWIPで保存
  2. letter_openerで、管理者とメンターのアドレスに送信されていないことを確認
  3. 管理者・メンターでログインし、画面右上のサイト内通知が届いていないことを確認
  4. Discord通知のログが出力されないことを確認
  5. 再度受講生としてログインし、WIPにしていたDocsを公開し、メールが送信されていることを確認。
  6. 再び管理者・メンターでログインし、サイト内通知が届いていることを確認
  7. Discord通知のログを確認

Summary by CodeRabbit

Summary by CodeRabbit

  • リファクタリング
    • ページ作成および更新時の通知方法がActiveSupport通知に切り替えられ、内部イベントシステムが刷新されました。動作や画面上の変化はありません。

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Jul 26, 2025

Walkthrough

PagesControllerのイベント発行方法をNewspaper.publishからActiveSupport::Notifications.instrumentへと移行し、PageNotifierのシグネチャをActiveSupportの通知仕様に合わせて修正しました。さらに、関連する初期化ファイルでの購読設定もActiveSupportベースに変更されました。

Changes

ファイル/グループ 変更内容概要
コントローラー変更
app/controllers/pages_controller.rb
イベント発行をNewspaper.publishからActiveSupport::Notifications.instrumentに置換
モデル変更
app/models/page_notifier.rb
callメソッドの引数をActiveSupport通知のシグネチャ(5引数)に変更
ActiveSupport通知初期化
config/initializers/active_support_notifications.rb
PageNotifierpage.createpage.updateイベントに購読追加
Newspaper購読解除
config/initializers/newspaper.rb
PageNotifierNewspaperイベント購読(:page_create, :page_update)を削除

Sequence Diagram(s)

sequenceDiagram
    participant Controller as PagesController
    participant ASNotification as ActiveSupport::Notifications
    participant Notifier as PageNotifier

    Controller->>ASNotification: instrument('page.create', payload)
    ASNotification->>Notifier: call(_name, _started, _finished, _unique_id, payload)
    Notifier->>Notifier: ページ通知・更新処理
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

Suggested reviewers

  • komagata

Poem

うさぎの耳がピンと立つ、
新しい通知の風が吹く。
Newspaperから旅立って、
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/pages_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.77.0/lib/rubocop/config_loader_resolver.rb:309:in rescue in gem_config_path' /var/lib/gems/3.1.0/gems/rubocop-1.77.0/lib/rubocop/config_loader_resolver.rb:293:in gem_config_path'
/var/lib/gems/3.1.0/gems/rubocop-1.77.0/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.77.0/lib/rubocop/config_loader_resolver.rb:82:in reverse_each'
/var/lib/gems/3.1.0/gems/rubocop-1.77.0/lib/rubocop/config_loader_resolver.rb:82:in block in resolve_inheritance_from_gems' /var/lib/gems/3.1.0/gems/rubocop-1.77.0/lib/rubocop/config_loader_resolver.rb:76:in each_pair'
/var/lib/gems/3.1.0/gems/rubocop-1.77.0/lib/rubocop/config_loader_resolver.rb:76:in resolve_inheritance_from_gems' /var/lib/gems/3.1.0/gems/rubocop-1.77.0/lib/rubocop/config_loader.rb:66:in load_file'
/var/lib/gems/3.1.0/gems/rubocop-1.77.0/lib/rubocop/config_store.rb:29:in options_config=' /var/lib/gems/3.1.0/gems/rubocop-1.77.0/lib/rubocop/cli.rb:160:in act_on_options'
/var/lib/gems/3.1.0/gems/rubocop-1.77.0/lib/rubocop/cli.rb:47:in block in run' /var/lib/gems/3.1.0/gems/rubocop-1.77.0/lib/rubocop/cli.rb:81:in profile_if_needed'
/var/lib/gems/3.1.0/gems/rubocop-1.77.0/lib/rubocop/cli.rb:43:in run' /var/lib/gems/3.1.0/gems/rubocop-1.77.0/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.77.0/lib/rubocop/config_loader_resolver.rb:309:in rescue in gem_config_path' /var/lib/gems/3.1.0/gems/rubocop-1.77.0/lib/rubocop/config_loader_resolver.rb:293:in gem_config_path'
/var/lib/gems/3.1.0/gems/rubocop-1.77.0/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.77.0/lib/rubocop/config_loader_resolver.rb:82:in reverse_each'
/var/lib/gems/3.1.0/gems/rubocop-1.77.0/lib/rubocop/config_loader_resolver.rb:82:in block in resolve_inheritance_from_gems' /var/lib/gems/3.1.0/gems/rubocop-1.77.0/lib/rubocop/config_loader_resolver.rb:76:in each_pair'
/var/lib/gems/3.1.0/gems/rubocop-1.77.0/lib/rubocop/config_loader_resolver.rb:76:in resolve_inheritance_from_gems' /var/lib/gems/3.1.0/gems/rubocop-1.77.0/lib/rubocop/config_loader.rb:66:in load_file'
/var/lib/gems/3.1.0/gems/rubocop-1.77.0/lib/rubocop/config_store.rb:29:in options_config=' /var/lib/gems/3.1.0/gems/rubocop-1.77.0/lib/rubocop/cli.rb:160:in act_on_options'
/var/lib/gems/3.1.0/gems/rubocop-1.77.0/lib/rubocop/cli.rb:47:in block in run' /var/lib/gems/3.1.0/gems/rubocop-1.77.0/lib/rubocop/cli.rb:81:in profile_if_needed'
/var/lib/gems/3.1.0/gems/rubocop-1.77.0/lib/rubocop/cli.rb:43:in run' /var/lib/gems/3.1.0/gems/rubocop-1.77.0/exe/rubocop:19:in <top (required)>'
/usr/local/bin/rubocop:25:in load' /usr/local/bin/rubocop:25:in

'

app/models/page_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.77.0/lib/rubocop/config_loader_resolver.rb:309:in rescue in gem_config_path' /var/lib/gems/3.1.0/gems/rubocop-1.77.0/lib/rubocop/config_loader_resolver.rb:293:in gem_config_path'
/var/lib/gems/3.1.0/gems/rubocop-1.77.0/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.77.0/lib/rubocop/config_loader_resolver.rb:82:in reverse_each'
/var/lib/gems/3.1.0/gems/rubocop-1.77.0/lib/rubocop/config_loader_resolver.rb:82:in block in resolve_inheritance_from_gems' /var/lib/gems/3.1.0/gems/rubocop-1.77.0/lib/rubocop/config_loader_resolver.rb:76:in each_pair'
/var/lib/gems/3.1.0/gems/rubocop-1.77.0/lib/rubocop/config_loader_resolver.rb:76:in resolve_inheritance_from_gems' /var/lib/gems/3.1.0/gems/rubocop-1.77.0/lib/rubocop/config_loader.rb:66:in load_file'
/var/lib/gems/3.1.0/gems/rubocop-1.77.0/lib/rubocop/config_store.rb:29:in options_config=' /var/lib/gems/3.1.0/gems/rubocop-1.77.0/lib/rubocop/cli.rb:160:in act_on_options'
/var/lib/gems/3.1.0/gems/rubocop-1.77.0/lib/rubocop/cli.rb:47:in block in run' /var/lib/gems/3.1.0/gems/rubocop-1.77.0/lib/rubocop/cli.rb:81:in profile_if_needed'
/var/lib/gems/3.1.0/gems/rubocop-1.77.0/lib/rubocop/cli.rb:43:in run' /var/lib/gems/3.1.0/gems/rubocop-1.77.0/exe/rubocop:19:in <top (required)>'
/usr/local/bin/rubocop:25:in load' /usr/local/bin/rubocop:25:in

'

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b9abf42 and f7d5bdc.

📒 Files selected for processing (4)
  • app/controllers/pages_controller.rb (2 hunks)
  • app/models/page_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/models/page_notifier.rb
  • app/controllers/pages_controller.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_newspaper_to_notifications_in_page_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.
    • Explain this complex logic.
    • 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. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • 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 src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

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

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

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.

Documentation and Community

  • 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 Miya096jp requested a review from ryufuta July 26, 2025 05:12
@Miya096jp
Copy link
Copy Markdown
Contributor Author

@ryufuta

お疲れ様です!
お手隙の時にレビューをお願いしてよろしいでしょうか?

@Miya096jp Miya096jp self-assigned this Jul 26, 2025
@ryufuta ryufuta marked this pull request as ready for review July 26, 2025 06:07
@github-actions github-actions bot requested a review from komagata July 26, 2025 06:07
@ryufuta
Copy link
Copy Markdown
Contributor

ryufuta commented Jul 26, 2025

@Miya096jp
依頼ありがとうございます!
数日以内にレビューします!
(PRがDraftになっていたのでReady for reviewボタンを勝手に押してしまいました🙇🏻‍♂️PR作成者以外でも押せてしまうのですね)

@Miya096jp
Copy link
Copy Markdown
Contributor Author

@ryufuta

すみません、変更ありがとうございました🙏
よろしくお願いいたします!

Copy link
Copy Markdown
Contributor

@ryufuta ryufuta left a comment

Choose a reason for hiding this comment

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

確認しました!
問題ないのでApporveします🙆🏻‍♂️

変更手順がわかりやすかったです👍
また、修正が全部完了するまで中断するのではなく完了したところまででPRを作るのはチームとしても個人としても効率的だと思ったので今後見習いたいと思いました!

@Miya096jp
Copy link
Copy Markdown
Contributor Author

@ryufuta
ありがとうございました!
Discriptionを何度も書きなおしたかいがありました😊

@komagata
お疲れ様です!
レビューをお願いいたします🙏

@komagata
Copy link
Copy Markdown
Member

@Miya096jp conflictの修正をお願いします。

@Miya096jp Miya096jp force-pushed the chore/replace_newspaper_to_notifications_in_page_notifier branch from b9abf42 to f7d5bdc Compare July 29, 2025 00:59
@Miya096jp
Copy link
Copy Markdown
Contributor Author

@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 komagata merged commit 500cf99 into main Jul 29, 2025
5 checks passed
@komagata komagata deleted the chore/replace_newspaper_to_notifications_in_page_notifier branch July 29, 2025 20:08
@github-actions github-actions bot mentioned this pull request Jul 29, 2025
87 tasks
@Miya096jp
Copy link
Copy Markdown
Contributor Author

@komagata

本番環境でのチェックについてのお願いです。
Docs投稿時の通知機能の動作確認のため、こちらのDocsを作成しました。サイト通知とDiscord通知については確認が取れておりますので、メール通知が届いているかのご確認をよろしくお願いいたします🙇🏻

@komagata
Copy link
Copy Markdown
Member

@Miya096jp メールで届いておりました〜

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.

3 participants