From 5e11f08e9ae4a0be8ff34e7d506c548cba662180 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 18 Nov 2026 09:45:28 +0000 Subject: [PATCH 1/2] Build the worker image again on armv7 The uv image is pinned by digest, and that index has no armv7 build, so the armv7 worker build on main fails with "no match for platform in manifest". uv only runs on the build machine, so take it for the build platform, as reckon already does. --- workers/Dockerfile | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/workers/Dockerfile b/workers/Dockerfile index cb56115..524a5f1 100644 --- a/workers/Dockerfile +++ b/workers/Dockerfile @@ -4,8 +4,11 @@ # --- build: resolve the locked dependencies and build the kit's wheel --- # Base images and uv are pinned by digest; Dependabot moves the digests weekly. +# uv only runs on the build machine; its image has no armv7 build, so it is taken +# for the build platform instead of each target one. +FROM --platform=$BUILDPLATFORM ghcr.io/astral-sh/uv:0.11.32@sha256:df4cae8f3a96d175e2e5f992e597550000edbe78fdc2594d5cd8de1a217f504c AS uv FROM --platform=$BUILDPLATFORM python:3.15-slim@sha256:65a65fc7b30b06cb6df4930fd4650697cb23f4c2698ab81fc87e4b031bc36928 AS build -COPY --from=ghcr.io/astral-sh/uv:0.11.32@sha256:df4cae8f3a96d175e2e5f992e597550000edbe78fdc2594d5cd8de1a217f504c /uv /usr/local/bin/uv +COPY --from=uv /uv /usr/local/bin/uv WORKDIR /src COPY pyproject.toml uv.lock README.md ./ COPY src/ src/ From d27ad9c7b79251b075bfabd210f802572207729e Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 18 Nov 2026 09:45:29 +0000 Subject: [PATCH 2/2] Wait for running jobs before the app shuts down A catch-up run started when the server starts runs in the background and records its result when it ends. When the app stopped first, as tests do as soon as they finish, that write hit a closed app and could crash the test run (seen in shoppa). Each job now tracks its runs, and the app waits for them on terminate; runs that would start after that are skipped. --- backend/jobs/jobs.go | 42 +++++++++++++++++++++++++++++++++++++-- backend/jobs/jobs_test.go | 36 +++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+), 2 deletions(-) diff --git a/backend/jobs/jobs.go b/backend/jobs/jobs.go index 44e15cd..dba188a 100644 --- a/backend/jobs/jobs.go +++ b/backend/jobs/jobs.go @@ -39,12 +39,50 @@ func MustAdd(app core.App, name, cronExpr string, fn Func) { if err != nil { panic(fmt.Sprintf("job %q: %v", name, err)) } - app.Cron().MustAdd(name, cronExpr, func() { Run(app, name, fn) }) + runs := &background{} + app.Cron().MustAdd(name, cronExpr, func() { + runs.do(func() { Run(app, name, fn) }) + }) app.OnServe().BindFunc(func(se *core.ServeEvent) error { - go catchUp(se.App, name, schedule, fn, time.Now()) + now := time.Now() + go runs.do(func() { catchUp(se.App, name, schedule, fn, now) }) return se.Next() }) + + // the app waits for a running job before it closes its database, so a run + // never writes to a closed app + app.OnTerminate().BindFunc(func(e *core.TerminateEvent) error { + runs.stop() + return e.Next() + }) +} + +// background tracks one job's runs so the app can wait for them when it stops. +// Once stopped, new runs are skipped. +type background struct { + mu sync.Mutex + wg sync.WaitGroup + stopped bool +} + +func (b *background) do(f func()) { + b.mu.Lock() + if b.stopped { + b.mu.Unlock() + return + } + b.wg.Add(1) + b.mu.Unlock() + defer b.wg.Done() + f() +} + +func (b *background) stop() { + b.mu.Lock() + b.stopped = true + b.mu.Unlock() + b.wg.Wait() } // Run runs a job now and records the result. A run is skipped while the diff --git a/backend/jobs/jobs_test.go b/backend/jobs/jobs_test.go index b25e2e6..7b4debb 100644 --- a/backend/jobs/jobs_test.go +++ b/backend/jobs/jobs_test.go @@ -191,3 +191,39 @@ func TestSignInIsRateLimited(t *testing.T) { t.Errorf("rate limits = %+v", r) } } + +func TestShutdownWaitsForARunningJob(t *testing.T) { + a := newApp(t) + col, _ := a.FindCollectionByNameOrId(Collection) + rec := core.NewRecord(col) + rec.Set("name", "slow") + rec.Set("last_run", time.Now().Add(-time.Hour)) + if err := a.Save(rec); err != nil { + t.Fatal(err) + } + started, release := make(chan struct{}), make(chan struct{}) + MustAdd(a, "slow", "* * * * *", func(core.App) error { + close(started) + <-release + return nil + }) + if err := a.OnServe().Trigger(&core.ServeEvent{App: a}, func(*core.ServeEvent) error { return nil }); err != nil { + t.Fatal(err) + } + <-started + + stopped := make(chan time.Time) + go a.OnTerminate().Trigger(&core.TerminateEvent{App: a}, func(*core.TerminateEvent) error { + stopped <- lastRun(t, a, "slow").GetDateTime("last_run").Time() + return nil + }) + select { + case <-stopped: + t.Fatal("the app stopped while the job was still running") + case <-time.After(100 * time.Millisecond): + } + close(release) + if got := <-stopped; time.Since(got) > time.Minute { + t.Errorf("last_run = %v, want the run that just finished", got) + } +}