Compare commits
No commits in common. "59aa1733843c19ae66595efd3610d1062086f5fd" and "9cca5cc41babbd4d6491f5253e09edb8ae8da256" have entirely different histories.
59aa173384
...
9cca5cc41b
@ -84,27 +84,12 @@ func (r *BuildAuditRepository) Update(ctx context.Context, taskID string, result
|
|||||||
}
|
}
|
||||||
|
|
||||||
// UpdateStatus updates the status and worker assignment when a task is claimed.
|
// UpdateStatus updates the status and worker assignment when a task is claimed.
|
||||||
// When status is "running" (task claimed for execution/retry), this also clears
|
|
||||||
// any stale result and completed_at from previous failed attempts.
|
|
||||||
func (r *BuildAuditRepository) UpdateStatus(ctx context.Context, taskID string, status domain.BuildStatus, workerID string) error {
|
func (r *BuildAuditRepository) UpdateStatus(ctx context.Context, taskID string, status domain.BuildStatus, workerID string) error {
|
||||||
// When a task transitions to running (claimed for execution or retry),
|
res, err := r.db.ExecContext(ctx, `
|
||||||
// clear stale result data from any previous failed attempts.
|
UPDATE build_audit
|
||||||
var query string
|
SET status = $2, worker_id = $3
|
||||||
if status == domain.BuildStatusRunning {
|
WHERE task_id = $1
|
||||||
query = `
|
`, taskID, status, nullString(workerID))
|
||||||
UPDATE build_audit
|
|
||||||
SET status = $2, worker_id = $3, result = NULL, completed_at = NULL, started_at = NOW()
|
|
||||||
WHERE task_id = $1
|
|
||||||
`
|
|
||||||
} else {
|
|
||||||
query = `
|
|
||||||
UPDATE build_audit
|
|
||||||
SET status = $2, worker_id = $3
|
|
||||||
WHERE task_id = $1
|
|
||||||
`
|
|
||||||
}
|
|
||||||
|
|
||||||
res, err := r.db.ExecContext(ctx, query, taskID, status, nullString(workerID))
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("update build audit status: %w", err)
|
return fmt.Errorf("update build audit status: %w", err)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -60,11 +60,9 @@ func (r *WorkQueueRepository) Dequeue(ctx context.Context, workerID string) (*do
|
|||||||
var resultJSON []byte
|
var resultJSON []byte
|
||||||
var errorMsg sql.NullString
|
var errorMsg sql.NullString
|
||||||
|
|
||||||
// Clear stale error/completed_at when claiming for execution or retry.
|
|
||||||
// This prevents the API from returning confusing "running" status with stale error messages.
|
|
||||||
err := r.db.QueryRowContext(ctx, `
|
err := r.db.QueryRowContext(ctx, `
|
||||||
UPDATE work_queue
|
UPDATE work_queue
|
||||||
SET status = 'running', worker_id = $1, started_at = NOW(), error = NULL, completed_at = NULL
|
SET status = 'running', worker_id = $1, started_at = NOW()
|
||||||
WHERE id = (
|
WHERE id = (
|
||||||
SELECT id FROM work_queue
|
SELECT id FROM work_queue
|
||||||
WHERE status = 'pending'
|
WHERE status = 'pending'
|
||||||
|
|||||||
@ -94,17 +94,10 @@ func (g *PodGitOperations) CloneRepo(ctx context.Context, podName, workDir, clon
|
|||||||
// Verify the remote URL matches the expected clone URL
|
// Verify the remote URL matches the expected clone URL
|
||||||
currentRemote, err := g.runGitInPodOutput(ctx, podName, workDir, "config", "--get", "remote.origin.url")
|
currentRemote, err := g.runGitInPodOutput(ctx, podName, workDir, "config", "--get", "remote.origin.url")
|
||||||
currentRemote = strings.TrimSpace(currentRemote)
|
currentRemote = strings.TrimSpace(currentRemote)
|
||||||
|
|
||||||
// Strip token from currentRemote for comparison, since clone stores the authenticated URL
|
|
||||||
// Format: https://token:TOKEN@host/path -> https://host/path
|
|
||||||
normalizedRemote := currentRemote
|
|
||||||
if idx := strings.Index(currentRemote, "@"); idx != -1 && strings.HasPrefix(currentRemote, "https://") {
|
|
||||||
normalizedRemote = "https://" + currentRemote[idx+1:]
|
|
||||||
}
|
|
||||||
expectedURL := cloneURL
|
expectedURL := cloneURL
|
||||||
|
|
||||||
// Normalize URLs for comparison (both should be HTTPS without credentials)
|
// Normalize URLs for comparison (both should be HTTPS)
|
||||||
if err == nil && normalizedRemote == expectedURL {
|
if err == nil && currentRemote == expectedURL {
|
||||||
log.Info("workspace is already a git repo with correct remote, pulling latest",
|
log.Info("workspace is already a git repo with correct remote, pulling latest",
|
||||||
logging.FieldPodName, podName,
|
logging.FieldPodName, podName,
|
||||||
"workDir", workDir,
|
"workDir", workDir,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user