feat(go): scheduled bank sync (Go only)
The Go server now runs sync -> infer -> flush-cache by itself at the times in SYNC_SCHEDULE (comma-separated HH:MM, default 04:00, "off" disables), read in SYNC_TZ (default Europe/Prague). Nothing runs at startup; an invalid value stops the server with an error. - internal/scheduler: time-of-day parsing, Next, and the run loop - banksync.Runner: one lock shared by /sync-bank and the scheduler so runs never overlap, plus the status of the last run - footer shows the last sync since start and the next scheduled run - binary embeds time/tzdata because the Alpine image has no zone data Deliberately not implemented in the legacy Python app, which is being phased out; recorded in CLAUDE.md under "Deliberately Go-only features". Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fuj-management/go/internal/scheduler"
|
||||
"fuj-management/go/internal/services/banksync"
|
||||
"io"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestSyncInfo(t *testing.T) {
|
||||
now := time.Date(2026, 10, 8, 12, 0, 0, 0, time.UTC)
|
||||
four := []scheduler.TimeOfDay{{Hour: 4}}
|
||||
|
||||
ok := banksync.NewRunner(func(context.Context, io.Writer) error { return nil })
|
||||
if got := syncInfo(ok, four, time.UTC, now); got != "no sync since start | next 2026-10-09 04:00" {
|
||||
t.Errorf("before any run: %q", got)
|
||||
}
|
||||
if err := ok.Run(context.Background(), "scheduled", io.Discard); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
got := syncInfo(ok, nil, time.UTC, now)
|
||||
if !strings.HasPrefix(got, "last sync ") || !strings.HasSuffix(got, "(scheduled) ok | scheduled sync off") {
|
||||
t.Errorf("after ok run, schedule off: %q", got)
|
||||
}
|
||||
|
||||
bad := banksync.NewRunner(func(context.Context, io.Writer) error { return errors.New("boom") })
|
||||
_ = bad.Run(context.Background(), "manual", io.Discard)
|
||||
if got := syncInfo(bad, four, time.UTC, now); !strings.Contains(got, "(manual) FAILED | next 2026-10-09 04:00") {
|
||||
t.Errorf("after failed run: %q", got)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user