Synchronize connected accounts twice a day
One named syncInterval replaces the two 24-hour literals in the scheduler: a successful run now waits 12 hours, and an account becomes due again 12 hours after its last successful sync. Two background fetches a day stay inside Enable Banking's documented allowance of roughly four per account per day, which a failing sync's hourly retries also draw from, so the bank rate limits that prompted this are no more likely than before.
This commit is contained in:
@@ -371,6 +371,9 @@ func TestSyncSchedulingRespectsTheBanksOwnRetryTime(t *testing.T) {
|
||||
waiting := operational{LastSync: stale, SyncError: "N26: rate limited", SyncRetryAt: now.Add(3 * time.Hour).Format(time.RFC3339)}
|
||||
broken := operational{LastSync: stale, SyncError: "Trade Republic: retrieval failed"}
|
||||
healthy := operational{LastSync: now.Format(time.RFC3339)}
|
||||
// Twice daily: still fresh at six hours, due again after thirteen.
|
||||
fresh := operational{LastSync: now.Add(-6 * time.Hour).Format(time.RFC3339)}
|
||||
overdue := operational{LastSync: now.Add(-13 * time.Hour).Format(time.RFC3339)}
|
||||
elapsed := operational{LastSync: stale, SyncError: waiting.SyncError, SyncRetryAt: now.Add(-time.Minute).Format(time.RFC3339)}
|
||||
cases := []struct {
|
||||
name string
|
||||
@@ -384,6 +387,8 @@ func TestSyncSchedulingRespectsTheBanksOwnRetryTime(t *testing.T) {
|
||||
{"deadline elapsed", elapsed, false, 0, true},
|
||||
{"failure without a deadline", broken, false, 0, true},
|
||||
{"recent success", healthy, false, time.Minute, false},
|
||||
{"halfway through the interval", fresh, false, time.Minute, false},
|
||||
{"interval elapsed", overdue, false, 0, true},
|
||||
}
|
||||
for _, tt := range cases {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
@@ -399,7 +404,7 @@ func TestSyncSchedulingRespectsTheBanksOwnRetryTime(t *testing.T) {
|
||||
if backoff := syncBackoff(now, broken); backoff != time.Hour {
|
||||
t.Fatalf("failure backoff = %s, want hourly retries", backoff)
|
||||
}
|
||||
if backoff := syncBackoff(now, healthy); backoff != 24*time.Hour {
|
||||
t.Fatalf("successful backoff = %s, want daily synchronization", backoff)
|
||||
if backoff := syncBackoff(now, healthy); backoff != 12*time.Hour {
|
||||
t.Fatalf("successful backoff = %s, want twice-daily synchronization", backoff)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user