fix(catchup): guard on real in-flight backup check; add scheduler tests
This commit is contained in:
@@ -270,6 +270,22 @@ func (s *Store) LatestJobByKind(ctx context.Context, hostID, kind string) (*Job,
|
||||
return &j, nil
|
||||
}
|
||||
|
||||
// HasActiveBackupJob reports whether the host has a backup job that is
|
||||
// still queued or running. The catch-up scheduler uses this to avoid
|
||||
// dispatching a duplicate backup alongside one already in flight
|
||||
// (hosts.current_job_id is not maintained, so this is the authoritative
|
||||
// in-flight check).
|
||||
func (s *Store) HasActiveBackupJob(ctx context.Context, hostID string) (bool, error) {
|
||||
var exists bool
|
||||
err := s.db.QueryRowContext(ctx,
|
||||
`SELECT EXISTS(SELECT 1 FROM jobs WHERE host_id = ? AND kind = 'backup' AND status IN ('queued','running'))`,
|
||||
hostID).Scan(&exists)
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("store: has active backup job: %w", err)
|
||||
}
|
||||
return exists, nil
|
||||
}
|
||||
|
||||
// HasJobOfKind reports whether any job of the given kind exists for
|
||||
// this host, regardless of status. Used by the auto-init path on
|
||||
// agent hello to decide whether to dispatch a fresh `restic init` —
|
||||
|
||||
Reference in New Issue
Block a user