mirror of https://github.com/harness/drone.git
delete single job func added to job package (#932)
parent
efa51d81d9
commit
14e241f764
|
@ -483,3 +483,22 @@ func (s *JobStore) DeleteOld(ctx context.Context, olderThan time.Time) (int64, e
|
|||
|
||||
return n, nil
|
||||
}
|
||||
|
||||
// DeleteByID deletes a job by its unique identifier.
|
||||
func (s *JobStore) DeleteByUID(ctx context.Context, jobUID string) error {
|
||||
stmt := database.Builder.
|
||||
Delete("jobs").
|
||||
Where("job_uid = ?", jobUID)
|
||||
|
||||
sql, args, err := stmt.ToSql()
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to convert delete job query to sql: %w", err)
|
||||
}
|
||||
db := dbtx.GetAccessor(ctx, s.db)
|
||||
|
||||
_, err = db.ExecContext(ctx, sql, args...)
|
||||
if err != nil {
|
||||
return database.ProcessSQLErrorf(err, "failed to execute delete job query")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -644,6 +644,14 @@ func (s *Scheduler) PurgeJobsByGroupID(ctx context.Context, jobGroupID string) (
|
|||
return n, nil
|
||||
}
|
||||
|
||||
func (s *Scheduler) PurgeJobByUID(ctx context.Context, jobUID string) error {
|
||||
err := s.store.DeleteByUID(ctx, jobUID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to delete job with id=%s: %w", jobUID, err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func mapToProgressMany(jobs []*Job) []Progress {
|
||||
if jobs == nil {
|
||||
return nil
|
||||
|
|
|
@ -59,4 +59,7 @@ type Store interface {
|
|||
|
||||
// DeleteOld removes non-recurring jobs that have finished execution or have failed.
|
||||
DeleteOld(ctx context.Context, olderThan time.Time) (int64, error)
|
||||
|
||||
// DeleteByUID deletes a job by its unique identifier.
|
||||
DeleteByUID(ctx context.Context, jobUID string) error
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue