feat: Allow resource syncs to self update#1492
Open
scolastico wants to merge 1 commit into
Open
Conversation
Author
|
Even tho i tested this, i would recommend more indepth testing. Im currently trying to build a beta release in my repo, which i would test in a prod env. Tho as first tests seem successfull i update this pr from draft to review ready. |
Author
|
Created a ci for unstable releases of my changes: https://github.com/scolastico/komodo/tree/unstable-release |
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.
Let resource syncs sync themselves
Fixes #676
What this does
A resource sync can declare itself among the resources it manages. Before
this change, running such a sync - when its own config had changed - always
failed with
ResourceSync busyand left the sync stuck inPendingwithno clear recovery path. The only workarounds were removing the sync's own
declaration from the TOML, or hand-editing the UI config to match git exactly.
This PR makes a sync able to apply changes to itself during its own run, adds
an opt-in to immediately re-run when a sync changes its own scope, and turns
the "a sync would delete itself" case into an explicit hard error instead of a
confusing busy failure.
Why it happened
When a sync runs, it takes its own action-state lock (
syncing = true) for theentire run. Applying the sync's own changes goes through
resource::update::<ResourceSync>, which starts with a busy check:Because the sync is the thing holding the lock, this check always trips for the
sync's own entry - so it could never converge.
How it works
1. Apply self-updates, bypassing the busy check
resource::updatewas split intoupdate(unchanged, busy-checked) and a newupdate_ignore_busy, sharing a privateupdate_inner(..., check_busy: bool).No other call sites change.
execute_self_sync_updatespulls the sync's own entry out of theResourceSyncdeltas and applies the config update directly viaupdate_ignore_busy. This is safe: it runs sequentially as part of thein-progress sync, not concurrently. (Tag/description/template meta updates
already worked, since
update_metahas no busy check.)2. Optional re-run when a sync changes its own scope (
rerun_on_self_change)A run reconciles against the config that was active when the run started. If a
sync changes its own config mid-run (e.g. a new
resource_path), that new scopeonly takes effect on the next run - the end-of-run
RefreshResourceSyncPendingcorrectly recomputes pending against the new config, so the sync simply shows
Pendingagain (it does not get falsely marked "in sync").New opt-in config field
rerun_on_self_change(defaultfalse): when the syncsuccessfully changed its own config during a pass, run one more pass immediately
to apply the new scope, instead of waiting for an external trigger.
To support this,
RunSync::resolvewas refactored so the per-pass reconciliationlives in
execute_sync_pass(...), driven by a small loop hard-capped atMAX_SYNC_PASSES = 2. The cap guarantees termination even if a sync's TOML neverquite diff-matches itself; if it's still
Pendingafter the second pass it staysPending.3. A sync can never delete itself (hard fail)
If
delete/managedmode is enabled and the running sync is not declared inits own resource files, it would otherwise be marked for deletion. This now
hard-fails the run up front - before any resource is mutated - with a clear
message, rather than silently skipping the deletion or failing as "busy":
Failing early (right after deltas are computed) avoids a half-applied sync.
Behavior summary
ResourceSync busy, stuckPendingrerun_on_self_changeoff (default)Pendingrerun_on_self_changeonResourceSync busyChanges
bin/core/src/resource/mod.rs- splitupdateintoupdate/update_ignore_busy/update_inner(check_busy).bin/core/src/sync/execute.rs-execute_self_sync_updates(applies thesync's own update, bypassing busy; returns whether config changed).
bin/core/src/api/execute/sync.rs- extractedexecute_sync_pass, added thecapped re-run loop and the early self-delete hard fail.
client/core/rs/src/entities/sync.rs- newrerun_on_self_changeconfigfield (default
false).client/core/ts/src/types.ts,ui/public/client/types.d.ts- generated TStype for the new field.
ui/src/resources/sync/config.tsx- "Re-run On Self Change" toggle.docsite/docs/automate/sync-resources.md- documents self-managing syncs, thenew option, and the self-delete hard fail.
Testing
cargo check -p komodo_coreand-p komodo_clientpass with no warnings.Screenshots