Skip to content

AnswererWatcherをnewspaperからActiveSupport::Notificationsに移行#8835

Merged
komagata merged 2 commits intomainfrom
chore/replace-answer_watcher
Jun 20, 2025
Merged

AnswererWatcherをnewspaperからActiveSupport::Notificationsに移行#8835
komagata merged 2 commits intomainfrom
chore/replace-answer_watcher

Conversation

@komagata
Copy link
Copy Markdown
Member

@komagata komagata commented Jun 20, 2025

Summary

  • AnswererWatcherクラスをnewspaperからActiveSupport::Notificationsのsubscribeの仕組みに移行
  • 今後のnewspaper廃止作業のサンプルケースとして実装

変更内容

  • config/initializers/active_support_notifications.rb を新規作成し、ActiveSupport::Notificationsでのサブスクライブを設定
  • AnswererWatcher#call メソッドをActiveSupport::Notificationsの標準インターフェースに対応(引数を5つに変更)
  • API::AnswersControllerNewspaper.publish(:answer_create, ...)ActiveSupport::Notifications.instrument('answer.create', ...) に変更
  • config/initializers/newspaper.rb からAnswererWatcherの登録を削除

Test plan

  • 質問に回答した際に、回答者が自動的に質問をwatchするか確認
  • 既にwatchしている質問に回答した場合、重複してwatchが作成されないか確認
  • 他の既存機能に影響がないか確認

Summary by CodeRabbit

  • リファクタリング
    • 「回答作成」イベントの通知方法が独自システムからRails標準の通知機構に切り替わりました。
  • その他
    • 内部イベント監視の設定が更新されました。ユーザー体験や機能に影響はありません。

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Jun 20, 2025

"""

Walkthrough

API::AnswersControllercreateアクションで新たにActiveSupport::Notifications.instrument('answer.create', answer: @answer)が追加され、AnswererWatcherNewspaperからActiveSupport::Notificationsanswer.createイベントを購読するように変更されました。これに伴い、AnswererWatcher#callの引数が変更され、Newspaperの購読は削除されました。また、phantom.config.jsonに新コマンドが追加されています。

Changes

ファイル/グループ 変更内容概要
app/controllers/api/answers_controller.rb createアクションでActiveSupport::Notifications.instrument('answer.create', answer: @answer)を追加
app/models/answerer_watcher.rb callメソッドの引数を(_name, _started, _finished, _unique_id, payload)に変更
config/initializers/active_support_notifications.rb AnswererWatcheranswer.createイベントに購読する初期化ファイルを新規追加
config/initializers/newspaper.rb AnswererWatcherNewspaperによるanswer_createイベント購読を削除
phantom.config.json "postCreate"コマンド配列に"mise trust"コマンドを追加

Sequence Diagram(s)

sequenceDiagram
    participant Controller as AnswersController
    participant ASNotifications as ActiveSupport::Notifications
    participant Watcher as AnswererWatcher

    Controller->>ASNotifications: instrument('answer.create', answer: @answer)
    ASNotifications-->>Watcher: call(_name, _started, _finished, _unique_id, payload)
    Watcher->>Watcher: answer監視・Watch作成
Loading

Possibly related issues

Poem

うさぎが耳をぴょこぴょこ立てて
新しい通知の風を感じるよ
新聞からお引越し、標準の道へ
答えの誕生をそっと見守る
Railsの森で今日もぴょんぴょん
みんなの答え、しっかりキャッチ!
🐇✨📬

"""

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

'

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

'


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5dca2c8 and f1d6e1d.

📒 Files selected for processing (2)
  • app/controllers/api/answers_controller.rb (1 hunks)
  • config/initializers/active_support_notifications.rb (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • config/initializers/active_support_notifications.rb
  • app/controllers/api/answers_controller.rb
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build_and_test
✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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 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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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.

- config/initializers/active_support_notifications.rbを追加
- AnswererWatcherクラスをActiveSupport::Notificationsのインターフェースに対応
- AnswersControllerでイベント発火をActiveSupport::Notifications.instrumentに変更
- newspaper.rbからAnswererWatcherの登録を削除
@komagata komagata force-pushed the chore/replace-answer_watcher branch from d466746 to 5dca2c8 Compare June 20, 2025 13:32
- AnswersControllerでActiveSupport::NotificationsとNewspaperの両方でイベント発火
- AnswererWatcherからデバッグログを削除
- active_support_notifications.rbでRails.application.reloader.to_prepareを使用
@komagata komagata merged commit 17294a6 into main Jun 20, 2025
2 checks passed
@komagata komagata deleted the chore/replace-answer_watcher branch June 20, 2025 17:12
@github-actions github-actions bot mentioned this pull request Jun 20, 2025
21 tasks
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.

1 participant