update cicd
This commit is contained in:
@@ -100,3 +100,82 @@ func (r *jobRepository) GetLatestByVideoID(ctx context.Context, videoID string)
|
||||
}
|
||||
return &job, nil
|
||||
}
|
||||
|
||||
func (r *jobRepository) AssignPendingJob(ctx context.Context, jobID string, agentID int64, now time.Time) (bool, error) {
|
||||
result, err := query.Job.WithContext(ctx).
|
||||
Where(query.Job.ID.Eq(strings.TrimSpace(jobID)), query.Job.Status.Eq("pending"), query.Job.Cancelled.Is(false)).
|
||||
Updates(map[string]any{"status": "running", "agent_id": agentID, "updated_at": now})
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
return result.RowsAffected > 0, nil
|
||||
}
|
||||
|
||||
func (r *jobRepository) MarkJobStatusIfCurrent(ctx context.Context, jobID string, fromStatuses []string, toStatus string, now time.Time, clearAgent bool) (bool, error) {
|
||||
jobID = strings.TrimSpace(jobID)
|
||||
updates := map[string]any{"status": toStatus, "updated_at": now}
|
||||
if clearAgent {
|
||||
updates["agent_id"] = nil
|
||||
}
|
||||
q := query.Job.WithContext(ctx).Where(query.Job.ID.Eq(jobID), query.Job.Status.In(fromStatuses...))
|
||||
result, err := q.Updates(updates)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
return result.RowsAffected > 0, nil
|
||||
}
|
||||
|
||||
func (r *jobRepository) CancelJobIfActive(ctx context.Context, jobID string, now time.Time) (bool, error) {
|
||||
result, err := query.Job.WithContext(ctx).
|
||||
Where(query.Job.ID.Eq(strings.TrimSpace(jobID)), query.Job.Status.In("pending", "running")).
|
||||
Updates(map[string]any{"status": "cancelled", "cancelled": true, "updated_at": now})
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
return result.RowsAffected > 0, nil
|
||||
}
|
||||
|
||||
func (r *jobRepository) RequeueJob(ctx context.Context, jobID string, retryCount int64, logs *string, now time.Time) (bool, error) {
|
||||
updates := map[string]any{"status": "pending", "cancelled": false, "progress": 0, "agent_id": nil, "retry_count": retryCount, "updated_at": now}
|
||||
if logs != nil {
|
||||
updates["logs"] = *logs
|
||||
}
|
||||
result, err := query.Job.WithContext(ctx).
|
||||
Where(query.Job.ID.Eq(strings.TrimSpace(jobID)), query.Job.Status.In("running", "pending", "failure", "cancelled")).
|
||||
Updates(updates)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
return result.RowsAffected > 0, nil
|
||||
}
|
||||
|
||||
func (r *jobRepository) MoveJobToFailure(ctx context.Context, jobID string, logs *string, now time.Time) (bool, error) {
|
||||
updates := map[string]any{"status": "failure", "agent_id": nil, "updated_at": now}
|
||||
if logs != nil {
|
||||
updates["logs"] = *logs
|
||||
}
|
||||
result, err := query.Job.WithContext(ctx).
|
||||
Where(query.Job.ID.Eq(strings.TrimSpace(jobID)), query.Job.Status.In("running", "pending")).
|
||||
Updates(updates)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
return result.RowsAffected > 0, nil
|
||||
}
|
||||
|
||||
func (r *jobRepository) UpdateProgressAndLogsIfRunning(ctx context.Context, jobID string, progress *float64, logs *string, now time.Time) (bool, error) {
|
||||
updates := map[string]any{"updated_at": now}
|
||||
if progress != nil {
|
||||
updates["progress"] = *progress
|
||||
}
|
||||
if logs != nil {
|
||||
updates["logs"] = *logs
|
||||
}
|
||||
result, err := query.Job.WithContext(ctx).
|
||||
Where(query.Job.ID.Eq(strings.TrimSpace(jobID)), query.Job.Status.Eq("running")).
|
||||
Updates(updates)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
return result.RowsAffected > 0, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user