feat: Add master training trigger endpoint#1201
Open
rhuret wants to merge 1 commit intogorse-io:masterfrom
Open
feat: Add master training trigger endpoint#1201rhuret wants to merge 1 commit intogorse-io:masterfrom
rhuret wants to merge 1 commit intogorse-io:masterfrom
Conversation
Expose POST /api/training/trigger on gorse-master to schedule a training run on demand while preserving the existing fit_period ticker. Add explicit in-memory training coordination so: - force=false schedules a run only when the master is idle - force=true cancels the active run and queues exactly one replacement run Return JSON responses for success and error cases, and add tests for: - method/auth/query validation - default force=false behavior - non-forced no-op while training is running - forced cancel-and-reschedule behavior Also treat context.Canceled as expected control flow for forced retraining so the canceled run stops promptly without emitting misleading cache/training error logs.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1201 +/- ##
==========================================
- Coverage 72.72% 72.54% -0.19%
==========================================
Files 88 88
Lines 16258 16390 +132
==========================================
+ Hits 11824 11890 +66
- Misses 3233 3299 +66
Partials 1201 1201 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds a dedicated master endpoint to trigger training on demand:
POST /api/training/triggerforce=falseschedules training only when the master is idleforce=truecancels the active training run and queues exactly one replacement runThe implementation keeps the existing
fit_period-driven background ticker andreuses the current master training pipeline instead of introducing a separate
execution path.
Why
Today, training is mainly driven by the periodic
fit_periodloop or indirectlythrough data import flows. That is not precise enough for operational workflows
where ingestion and training must stay synchronized.
In our case, ingestion and training are orchestrated by separate steps. Once an
external ingestion job finishes, we need a deterministic way to trigger a fresh
training cycle immediately instead of waiting for the next scheduled tick.
This reduces the gap between:
Without an explicit trigger, ingestion/training synchronization depends on timing
and cron alignment, which increases the risk of serving stale recommendations
after a successful data import.
Changes
POST /api/training/triggerongorse-mastercontext.Canceledforce=trueBehavior
Idle master
POST /api/training/trigger202 AcceptedPOST /api/training/trigger?force=true202 AcceptedTraining already running
POST /api/training/trigger200 OKPOST /api/training/trigger?force=true202 AcceptedValidation
Tested with:
go test ./masterCovered by tests for: