Skip to content

Commit 5dd6245

Browse files
author
zsbahtiar
committed
fix: job id
1 parent 050a6b6 commit 5dd6245

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

models/actions/run.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -436,8 +436,8 @@ func UpdateRun(ctx context.Context, run *ActionRun, cols ...string) error {
436436

437437
type ActionRunIndex db.ResourceIndex
438438

439-
// DeleteRunByIDs delete action_run and action_run_job.
440-
func DeleteRunByIDs(ctx context.Context, ids []int64) error {
439+
// DeleteRunByIDs delete action_task_step, action_task_output, action_task, action_run and action_run_job.
440+
func DeleteRunByIDs(ctx context.Context, runIDs, jobIDs []int64) error {
441441
ctx, committer, err := db.TxContext(ctx)
442442
if err != nil {
443443
return err
@@ -447,7 +447,7 @@ func DeleteRunByIDs(ctx context.Context, ids []int64) error {
447447
_, err = db.GetEngine(ctx).
448448
Table("action_task").
449449
Join("INNER", "action_task_step", "action_task.id = action_task_step.task_id").
450-
In("action_task.job_id", ids).
450+
In("action_task.job_id", jobIDs).
451451
Delete(ActionTaskStep{})
452452
if err != nil {
453453
return err
@@ -456,23 +456,23 @@ func DeleteRunByIDs(ctx context.Context, ids []int64) error {
456456
_, err = db.GetEngine(ctx).
457457
Table("action_task").
458458
Join("INNER", "action_task_output", "action_task.id = action_task_output.task_id").
459-
In("action_task.job_id", ids).
459+
In("action_task.job_id", jobIDs).
460460
Delete(ActionTaskOutput{})
461461
if err != nil {
462462
return err
463463
}
464464

465-
_, err = db.GetEngine(ctx).In("job_id", ids).Delete(ActionTask{})
465+
_, err = db.GetEngine(ctx).In("job_id", jobIDs).Delete(ActionTask{})
466466
if err != nil {
467467
return err
468468
}
469469

470-
_, err = db.GetEngine(ctx).In("run_id", ids).Delete(ActionRunJob{})
470+
_, err = db.GetEngine(ctx).In("id", jobIDs).Delete(ActionRunJob{})
471471
if err != nil {
472472
return err
473473
}
474474

475-
_, err = db.GetEngine(ctx).In("id", ids).Delete(ActionRun{})
475+
_, err = db.GetEngine(ctx).In("id", runIDs).Delete(ActionRun{})
476476
if err != nil {
477477
return err
478478
}

routers/web/repo/actions/actions.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,9 +449,19 @@ func DeleteRuns(ctx *context.Context) {
449449

450450
if len(actionRun) != len(req.ActionIDs) {
451451
ctx.ServerError("action ids not match with request", nil)
452+
return
453+
}
454+
actionRunJobs, err := actions_model.GetRunJobsByRunIDs(ctx, req.ActionIDs)
455+
if err != nil {
456+
ctx.ServerError("failed to get run jobs by run ids", err)
457+
return
458+
}
459+
var jobIDs []int64
460+
for _, actionRunJob := range actionRunJobs {
461+
jobIDs = append(jobIDs, actionRunJob.ID)
452462
}
453463

454-
err = actions_model.DeleteRunByIDs(ctx, req.ActionIDs)
464+
err = actions_model.DeleteRunByIDs(ctx, req.ActionIDs, jobIDs)
455465
if err != nil {
456466
ctx.ServerError("failed to delete action_run", err)
457467
return

0 commit comments

Comments
 (0)