fix: reduce battery drain from polling in embedded mode#6
fix: reduce battery drain from polling in embedded mode#6KoheiYamashita merged 2 commits intomainfrom
Conversation
Stop health check polling after backend reaches RUNNING state, and replace cron service's 1-second ticker with timer-based scheduling that sleeps until the next job is due. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! 組み込み環境、特にAndroidアプリのフォアグラウンドサービス内で動作するGoバックエンドにおいて、バッテリー消費の主要因となっていた2つのポーリング機構を最適化しました。これにより、CPUが不必要に起動し続けることを防ぎ、Dozeモードへの移行を妨げないことで、全体的なバッテリー寿命の改善に貢献します。 Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
このプルリクエストは、ポーリングに起因するバッテリー消費を削減するための重要な修正です。Kotlin側のヘルスチェックの停止と、Go側のcronサービスをタイマーベースの実行に切り替える変更は、どちらも適切に実装されています。特に、GoのrunLoopにおけるtime.Timerとnilチャネルを組み合わせた省電力化の実装は、効率的でGoの言語特性をうまく活かしています。また、関連するテストケースが追加されている点も素晴らしいです。全体として、コードの品質は高く、問題は見つかりませんでした。
Add SIGTERM handling to Go gateway so proc.destroy() triggers graceful shutdown and immediate port release. Add Mutex to GatewayProcessManager to prevent concurrent start/stop races between watchdog and settings observer. Add port release polling after process termination. Catch InterruptedIOException in log forwarding to prevent crash on shutdown. Defer settingsStore.update() until after setup complete API returns to avoid killing the gateway mid-request. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Merge duplicate parameter descriptions in buildParameters (#1) - Use map for DisabledActions lookup in isActionEnabled (#2) - Add URL scheme whitelist (http/https only) for open_url (#3) - Escape SQL LIKE wildcards in ContactsActionHandler (#4) - Fix JSON tag inconsistency: web_actions -> web (#5) - Add comprehensive tests for android tool (#6) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
📝 Description
組み込み版(embedded)で2つのポーリング機構がCPUを常時起こし続け、バッテリー消費の原因になっていた問題を修正。
GatewayProcessManager.pollHealth()がRUNNING状態遷移後も500ms間隔でHTTPポーリングを継続していたのを、RUNNING到達時点でコルーチンを終了するよう変更time.Timer+getNextWakeMS()で次のジョブの実行時刻まで正確にスリープする方式に変更。ジョブ0件時はCPU消費ゼロで完全スリープ🗣️ Type of Change
📚 Technical Context (Skip for Docs)
ヘルスチェック (Android/Kotlin)
pollHealth()でRUNNING遷移後にreturnを追加し、コルーチンを自然終了stopProcess()の既存キャンセル処理は完了済みJobに対してno-opなので安全Cronサービス (Go)
rescheduleCh chan struct{}(バッファ1) を追加し、ジョブの追加/削除/変更時にタイマーを即座に再計算nilチャネルのselectブロック特性を利用し、ジョブなし時は完全スリープAddJob,UpdateJob,RemoveJob,EnableJob,executeJobByIDの全mutationメソッドにnotifyReschedule()を追加🧪 Test Environment & Hardware
go test ./pkg/cron/ -v -count=1— 全29テスト PASS(既存27件 + 新規2件)☑️ Checklist
🤖 Generated with Claude Code