From ad84bcb992ba0552d582f8a6d53ac330f799a955 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Wed, 11 Mar 2026 18:49:14 +0200 Subject: feat(sync): enforce daily repo sync intervals --- internal/state/state.go | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'internal/state') diff --git a/internal/state/state.go b/internal/state/state.go index 3288db1..4d5f197 100644 --- a/internal/state/state.go +++ b/internal/state/state.go @@ -11,7 +11,7 @@ import ( // State represents the persistent state of gitsyncer type State struct { LastBatchRun time.Time `json:"lastBatchRun"` - // Per-repo sync tracking for throttling + // Per-repo sync tracking for default daily sync limits and optional throttling LastRepoSync map[string]time.Time `json:"lastRepoSync,omitempty"` NextRepoSyncAllowed map[string]time.Time `json:"nextRepoSyncAllowed,omitempty"` } @@ -117,6 +117,15 @@ func (s *State) SetRepoSync(repoName string, lastSync time.Time, nextAllowed tim s.NextRepoSyncAllowed[repoName] = nextAllowed } +// SetLastRepoSync updates only the last sync time for a repo. +func (s *State) SetLastRepoSync(repoName string, lastSync time.Time) { + if s == nil { + return + } + s.EnsureRepoMaps() + s.LastRepoSync[repoName] = lastSync +} + // SetNextRepoSyncAllowed updates only the next allowed sync time for a repo func (s *State) SetNextRepoSyncAllowed(repoName string, nextAllowed time.Time) { if s == nil { @@ -125,3 +134,11 @@ func (s *State) SetNextRepoSyncAllowed(repoName string, nextAllowed time.Time) { s.EnsureRepoMaps() s.NextRepoSyncAllowed[repoName] = nextAllowed } + +// ClearNextRepoSyncAllowed removes the next allowed sync time for a repo. +func (s *State) ClearNextRepoSyncAllowed(repoName string) { + if s == nil || s.NextRepoSyncAllowed == nil { + return + } + delete(s.NextRepoSyncAllowed, repoName) +} -- cgit v1.2.3