75f3dd141c
CodeQL / Analyze (go) (push) Has been cancelled
CodeQL / Analyze (actions) (push) Has been cancelled
CodeQL / Analyze (javascript-typescript) (push) Has been cancelled
CI and Release / lint-frontend (push) Has been cancelled
CI and Release / dockerfile-scan (push) Has been cancelled
CI and Release / test-frontend (push) Has been cancelled
CI and Release / lint-verification-agent (push) Has been cancelled
CI and Release / test-verification-agent (push) Has been cancelled
CI and Release / e2e-verification-agent (push) Has been cancelled
CI and Release / test-backend (push) Has been cancelled
CI and Release / build-dev-image (push) Has been cancelled
CI and Release / push-dev-image (push) Has been cancelled
CI and Release / build-image (push) Has been cancelled
CI and Release / build-verification-image (push) Has been cancelled
CI and Release / determine-version (push) Has been cancelled
CI and Release / push-image (push) Has been cancelled
CI and Release / push-verification-image (12) (push) Has been cancelled
CI and Release / lint-backend (push) Has been cancelled
CI and Release / push-verification-image (17) (push) Has been cancelled
CI and Release / push-verification-image (18) (push) Has been cancelled
CI and Release / release (push) Has been cancelled
CI and Release / publish-helm-chart (push) Has been cancelled
CI and Release / push-verification-image (13) (push) Has been cancelled
CI and Release / push-verification-image (14) (push) Has been cancelled
CI and Release / push-verification-image (15) (push) Has been cancelled
CI and Release / push-verification-image (16) (push) Has been cancelled
61 lines
1.4 KiB
Go
61 lines
1.4 KiB
Go
package runner
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"log/slog"
|
|
"time"
|
|
)
|
|
|
|
var diskWatchInterval = 3 * time.Second
|
|
|
|
// diskWatcher polls the job's written bytes and fires onLimitExceeded once when
|
|
// the footprint reaches the server-computed ceiling. It never trips on a probe
|
|
// error (a transient daemon hiccup must not fail a healthy restore). The caller
|
|
// owns the reaction: onLimitExceeded records the trip and cancels the job.
|
|
type diskWatcher struct {
|
|
probe diskUsageProber
|
|
ceilingBytes int64
|
|
interval time.Duration
|
|
onLimitExceeded func()
|
|
log *slog.Logger
|
|
}
|
|
|
|
func newDiskWatcher(
|
|
probe diskUsageProber, ceilingBytes int64, onLimitExceeded func(), log *slog.Logger,
|
|
) *diskWatcher {
|
|
return &diskWatcher{
|
|
probe: probe,
|
|
ceilingBytes: ceilingBytes,
|
|
interval: diskWatchInterval,
|
|
onLimitExceeded: onLimitExceeded,
|
|
log: log,
|
|
}
|
|
}
|
|
|
|
func (w *diskWatcher) run(ctx context.Context) {
|
|
ticker := time.NewTicker(w.interval)
|
|
defer ticker.Stop()
|
|
|
|
for {
|
|
used, err := w.probe.GetDiskUsageBytes(ctx)
|
|
switch {
|
|
case err != nil:
|
|
w.log.Debug("disk watch probe failed, will retry next tick", "error", err)
|
|
case used >= w.ceilingBytes:
|
|
w.log.Warn(fmt.Sprintf(
|
|
"job disk usage %d bytes reached ceiling %d bytes; aborting restore",
|
|
used, w.ceilingBytes))
|
|
w.onLimitExceeded()
|
|
|
|
return
|
|
}
|
|
|
|
select {
|
|
case <-ctx.Done():
|
|
return
|
|
case <-ticker.C:
|
|
}
|
|
}
|
|
}
|