summaryrefslogtreecommitdiff
path: root/internal/state
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-03-11 18:49:14 +0200
committerPaul Buetow <paul@buetow.org>2026-03-11 18:49:14 +0200
commitad84bcb992ba0552d582f8a6d53ac330f799a955 (patch)
tree2c3d386e090a8a52a45f52b0b424abb4143c0062 /internal/state
parent0011f18e8494a4e57dc277b826d56c0a1df041ce (diff)
feat(sync): enforce daily repo sync intervals
Diffstat (limited to 'internal/state')
-rw-r--r--internal/state/state.go19
1 files changed, 18 insertions, 1 deletions
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)
+}