fix: review fixes for webhook and auto mode (#8)
Clear available_* only when the deployed ref equals it, drop the unused poll source, stop leaking internal errors to CI, use the request-scoped logger, validate X-Request-ID, re-read jobs once after the timeout, report refused when no target ref exists, and tidy UI, deploy and docs.
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/jackc/pgx/v5"
|
||||
@@ -187,9 +188,10 @@ func (s *Store) JobProgress(ctx context.Context, agentID, jobID int64, chunk str
|
||||
// agentID: status, error, output (replacing what progress assembled),
|
||||
// started_at (the agent's, or the existing one if the agent sent none),
|
||||
// finished_at; to_ref = f.Ref when set. On success it also sets the
|
||||
// service's desired_ref = f.Ref and clears its available ref if that was
|
||||
// reported no later than the job was created (the job then deployed the
|
||||
// newest version), in the same transaction. Returns false if no
|
||||
// service's desired_ref = f.Ref and clears its available ref when that is
|
||||
// the ref the job was created for (ignoring any @digest) and was reported no
|
||||
// later than the job was created (that version is now running), in the same
|
||||
// transaction. Returns false if no
|
||||
// such active job belongs to agentID.
|
||||
func (s *Store) FinishJob(ctx context.Context, agentID, jobID int64, f model.JobFinish) (bool, error) {
|
||||
tx, err := s.pool.Begin(ctx)
|
||||
@@ -206,14 +208,17 @@ func (s *Store) FinishJob(ctx context.Context, agentID, jobID int64, f model.Job
|
||||
}
|
||||
var serviceID int64
|
||||
var createdAt time.Time
|
||||
var requestedRef string
|
||||
// requested is the job's to_ref as it was created, before f.Ref overwrites it.
|
||||
err = tx.QueryRow(ctx, `
|
||||
UPDATE update_jobs SET
|
||||
UPDATE update_jobs j SET
|
||||
status = $3, error = $4, output = $5, output_truncated = $6,
|
||||
to_ref = CASE WHEN $7::text <> '' THEN $7::text ELSE to_ref END,
|
||||
started_at = COALESCE($8, started_at), finished_at = $9
|
||||
WHERE id = $1 AND agent_id = $2 AND status IN ('queued', 'running')
|
||||
RETURNING service_id, created_at`,
|
||||
jobID, agentID, string(f.Status), f.Error, f.Output, f.OutputTruncated, f.Ref, startedAt, f.FinishedAt).Scan(&serviceID, &createdAt)
|
||||
to_ref = CASE WHEN $7::text <> '' THEN $7::text ELSE j.to_ref END,
|
||||
started_at = COALESCE($8, j.started_at), finished_at = $9
|
||||
FROM (SELECT id, to_ref FROM update_jobs WHERE id = $1) requested
|
||||
WHERE j.id = requested.id AND j.agent_id = $2 AND j.status IN ('queued', 'running')
|
||||
RETURNING j.service_id, j.created_at, requested.to_ref`,
|
||||
jobID, agentID, string(f.Status), f.Error, f.Output, f.OutputTruncated, f.Ref, startedAt, f.FinishedAt).Scan(&serviceID, &createdAt, &requestedRef)
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return false, nil
|
||||
}
|
||||
@@ -221,12 +226,13 @@ func (s *Store) FinishJob(ctx context.Context, agentID, jobID int64, f model.Job
|
||||
return false, fmt.Errorf("finish job: %w", err)
|
||||
}
|
||||
if f.Status == model.JobSucceeded {
|
||||
requestedRef, _, _ = strings.Cut(requestedRef, "@")
|
||||
if _, err := tx.Exec(ctx, `
|
||||
UPDATE services SET desired_ref = $2,
|
||||
available_ref = CASE WHEN available_at <= $3 THEN '' ELSE available_ref END,
|
||||
available_source = CASE WHEN available_at <= $3 THEN '' ELSE available_source END,
|
||||
available_at = CASE WHEN available_at <= $3 THEN NULL ELSE available_at END
|
||||
WHERE id = $1`, serviceID, f.Ref, createdAt); err != nil {
|
||||
available_ref = CASE WHEN available_ref = $4 AND available_at <= $3 THEN '' ELSE available_ref END,
|
||||
available_source = CASE WHEN available_ref = $4 AND available_at <= $3 THEN '' ELSE available_source END,
|
||||
available_at = CASE WHEN available_ref = $4 AND available_at <= $3 THEN NULL ELSE available_at END
|
||||
WHERE id = $1`, serviceID, f.Ref, createdAt, requestedRef); err != nil {
|
||||
return false, fmt.Errorf("finish job: desired ref: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user