@@ -162,6 +162,16 @@ func (s *Server) runSyncJobs() error {
162
162
continue
163
163
}
164
164
165
+ if ! entry .Status .LastExecutionTime .IsZero () && entry .Status .LastExecutionTime .Add (time .Duration (entry .Metadata .ScheduleFrequency )* time .Minute ).After (time .Now ()) {
166
+ s .Trace ().Msgf ("Sync job %s not ready to run" , entry .Id )
167
+ continue
168
+ }
169
+
170
+ if entry .Status .FailureCount >= s .config .System .MaxSyncFailureCount {
171
+ s .Trace ().Msgf ("Sync job %s has failed too many times, skipping" , entry .Id )
172
+ continue
173
+ }
174
+
165
175
_ , _ , err = s .runSyncJob (ctx , types.Transaction {}, entry , true , repoCache ) // each sync runs in its own transaction
166
176
if err != nil {
167
177
s .Error ().Err (err ).Msgf ("Error running sync job %s" , entry .Id )
@@ -172,7 +182,8 @@ func (s *Server) runSyncJobs() error {
172
182
return nil
173
183
}
174
184
175
- func (s * Server ) runSyncJob (ctx context.Context , inputTx types.Transaction , entry * types.SyncEntry , checkCommitHash bool , repoCache * RepoCache ) (* types.SyncJobStatus , []types.AppPathDomain , error ) {
185
+ func (s * Server ) runSyncJob (ctx context.Context , inputTx types.Transaction , entry * types.SyncEntry ,
186
+ checkCommitHash bool , repoCache * RepoCache ) (* types.SyncJobStatus , []types.AppPathDomain , error ) {
176
187
var tx types.Transaction
177
188
var err error
178
189
if inputTx .Tx == nil {
@@ -186,6 +197,7 @@ func (s *Server) runSyncJob(ctx context.Context, inputTx types.Transaction, entr
186
197
// No rollback here if transaction is passed in
187
198
}
188
199
200
+ s .Debug ().Msgf ("Running sync job %s" , entry .Id )
189
201
if repoCache == nil {
190
202
// Create a new repo cache if not passed in
191
203
repoCache , err = NewRepoCache (s )
@@ -213,8 +225,10 @@ func (s *Server) runSyncJob(ctx context.Context, inputTx types.Transaction, entr
213
225
status .Error = applyErr .Error ()
214
226
applyInfo = & types.AppApplyResponse {}
215
227
applyInfo .FilteredApps = lastRunApps
228
+ status .FailureCount ++
216
229
} else {
217
230
status .CommitId = applyInfo .CommitId
231
+ status .FailureCount = 0
218
232
}
219
233
220
234
status .ApplyResponse = * applyInfo
@@ -270,8 +284,8 @@ func (s *Server) runSyncJob(ctx context.Context, inputTx types.Transaction, entr
270
284
status .ApplyResponse .PromoteResults = promoteResults
271
285
}
272
286
}
273
- status .ApplyResponse = * applyInfo
274
287
288
+ status .ApplyResponse = * applyInfo
275
289
err = s .db .UpdateSyncStatus (ctx , tx , entry .Id , & status )
276
290
if err != nil {
277
291
return nil , nil , err
0 commit comments