Skip to content

Commit

Permalink
add job_id to gc task api
Browse files Browse the repository at this point in the history
Signed-off-by: lengrongfu <[email protected]>
  • Loading branch information
lengrongfu committed Aug 1, 2023
1 parent 39ec1e4 commit d97718e
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
3 changes: 3 additions & 0 deletions api/v2.0/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7888,6 +7888,9 @@ definitions:
job_status:
type: string
description: the status of gc job.
job_id:
type: string
description: the id of gc job.
deleted:
type: boolean
description: if gc job was deleted.
Expand Down
23 changes: 23 additions & 0 deletions src/server/v2.0/handler/gc.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,17 @@ func (g *gcAPI) GetGCHistory(ctx context.Context, params operation.GetGCHistoryP
if err != nil {
return g.SendError(ctx, err)
}

tasks, err := g.gcCtr.ListTasks(ctx, q.New(q.KeyWords{
"ExecutionID": exec.ID,
}))
if err != nil {
return g.SendError(ctx, err)
}
if len(tasks) == 0 {
return g.SendError(ctx, errors.New(nil).WithCode(errors.NotFoundCode).WithMessage("garbage collection %d log is not found", exec.ID))
}

hs = append(hs, &model.GCHistory{
ID: exec.ID,
Name: job.GarbageCollectionVendorType,
Expand All @@ -203,6 +214,7 @@ func (g *gcAPI) GetGCHistory(ctx context.Context, params operation.GetGCHistoryP
Schedule: &model.ScheduleParam{
Type: exec.Trigger,
},
JobID: tasks[0].JobID,
Status: exec.Status,
CreationTime: exec.StartTime,
UpdateTime: exec.UpdateTime,
Expand Down Expand Up @@ -234,6 +246,16 @@ func (g *gcAPI) GetGC(ctx context.Context, params operation.GetGCParams) middlew
return g.SendError(ctx, err)
}

tasks, err := g.gcCtr.ListTasks(ctx, q.New(q.KeyWords{
"ExecutionID": params.GCID,
}))
if err != nil {
return g.SendError(ctx, err)
}
if len(tasks) == 0 {
return g.SendError(ctx, errors.New(nil).WithCode(errors.NotFoundCode).WithMessage("garbage collection %d log is not found", params.GCID))
}

res := &model.GCHistory{
ID: exec.ID,
Name: job.GarbageCollectionVendorType,
Expand All @@ -243,6 +265,7 @@ func (g *gcAPI) GetGC(ctx context.Context, params operation.GetGCParams) middlew
Schedule: &model.ScheduleParam{
Type: exec.Trigger,
},
JobID: tasks[0].JobID,
CreationTime: exec.StartTime,
UpdateTime: exec.UpdateTime,
}
Expand Down
2 changes: 2 additions & 0 deletions src/server/v2.0/handler/model/gc.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ type GCHistory struct {
Parameters string `json:"job_parameters"`
Status string `json:"job_status"`
UUID string `json:"-"`
JobID string `json:"job_id"`
Deleted bool `json:"deleted"`
CreationTime time.Time `json:"creation_time"`
UpdateTime time.Time `json:"update_time"`
Expand All @@ -60,6 +61,7 @@ func (h *GCHistory) ToSwagger() *models.GCHistory {
JobParameters: h.Parameters,
Deleted: h.Deleted,
JobStatus: h.Status,
JobID: h.JobID,
Schedule: &models.ScheduleObj{
// covert MANUAL to Manual because the type of the ScheduleObj
// must be 'Hourly', 'Daily', 'Weekly', 'Custom', 'Manual' and 'None'
Expand Down

0 comments on commit d97718e

Please sign in to comment.