mirror of
https://github.com/go-gitea/gitea.git
synced 2025-02-20 11:43:57 +08:00
refactor: change to DeleteActionRunAndChild
This commit is contained in:
parent
71b773ac2e
commit
1a7a7e7127
@ -436,33 +436,27 @@ func UpdateRun(ctx context.Context, run *ActionRun, cols ...string) error {
|
||||
|
||||
type ActionRunIndex db.ResourceIndex
|
||||
|
||||
// DeleteRunByIDs delete action_task_step, action_task_output, action_task, action_run and action_run_job.
|
||||
func DeleteRunByIDs(ctx context.Context, runIDs, jobIDs []int64) error {
|
||||
// DeleteActionRunAndChild delete action_task_step, action_task_output, action_task, action_run and action_run_job.
|
||||
func DeleteActionRunAndChild(ctx context.Context, runIDs, jobIDs, taskIDs []int64) error {
|
||||
ctx, committer, err := db.TxContext(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer committer.Close()
|
||||
|
||||
_, err = db.GetEngine(ctx).
|
||||
Table("action_task").
|
||||
Join("INNER", "action_task_step", "action_task.id = action_task_step.task_id").
|
||||
In("action_task.job_id", jobIDs).
|
||||
_, err = db.GetEngine(ctx).In("task_id", taskIDs).
|
||||
Delete(ActionTaskStep{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = db.GetEngine(ctx).
|
||||
Table("action_task").
|
||||
Join("INNER", "action_task_output", "action_task.id = action_task_output.task_id").
|
||||
In("action_task.job_id", jobIDs).
|
||||
_, err = db.GetEngine(ctx).In("task_id", taskIDs).
|
||||
Delete(ActionTaskOutput{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = db.GetEngine(ctx).In("job_id", jobIDs).Delete(ActionTask{})
|
||||
_, err = db.GetEngine(ctx).In("id", taskIDs).Delete(ActionTask{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -445,10 +445,10 @@ func DeleteRuns(ctx *context.Context) {
|
||||
}
|
||||
|
||||
var (
|
||||
eg = new(errgroup.Group)
|
||||
actionRuns []*actions_model.ActionRun
|
||||
actionTasks []*actions_model.ActionTask
|
||||
jobIDs []int64
|
||||
eg = new(errgroup.Group)
|
||||
actionRuns []*actions_model.ActionRun
|
||||
jobIDs, taskIDs []int64
|
||||
taskLogFileNames []string
|
||||
)
|
||||
eg.Go(func() error {
|
||||
var err error
|
||||
@ -465,8 +465,16 @@ func DeleteRuns(ctx *context.Context) {
|
||||
for _, actionRunJob := range actionRunJobs {
|
||||
jobIDs = append(jobIDs, actionRunJob.ID)
|
||||
}
|
||||
actionTasks, err = actions_model.GetRunTasksByJobIDs(ctx, jobIDs)
|
||||
return err
|
||||
actionTasks, err := actions_model.GetRunTasksByJobIDs(ctx, jobIDs)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, actionTask := range actionTasks {
|
||||
taskIDs = append(taskIDs, actionTask.ID)
|
||||
taskLogFileNames = append(taskLogFileNames, actionTask.LogFilename)
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
||||
err := eg.Wait()
|
||||
@ -480,13 +488,13 @@ func DeleteRuns(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
err = actions_model.DeleteRunByIDs(ctx, req.ActionIDs, jobIDs)
|
||||
err = actions_model.DeleteActionRunAndChild(ctx, req.ActionIDs, jobIDs, taskIDs)
|
||||
if err != nil {
|
||||
ctx.ServerError("failed to delete action_run", err)
|
||||
return
|
||||
}
|
||||
|
||||
removeActionTaskLogFilenames(actionTasks)
|
||||
removeActionTaskLogFilenames(taskLogFileNames)
|
||||
|
||||
ctx.Status(http.StatusNoContent)
|
||||
}
|
||||
@ -495,15 +503,15 @@ type DeleteRunsRequest struct {
|
||||
ActionIDs []int64 `json:"actionIds"`
|
||||
}
|
||||
|
||||
func removeActionTaskLogFilenames(actionTasks []*actions_model.ActionTask) {
|
||||
func removeActionTaskLogFilenames(taskLogFileNames []string) {
|
||||
dirNameActionLog := "actions_log"
|
||||
go func() {
|
||||
for _, actionTask := range actionTasks {
|
||||
for _, taskLogFileName := range taskLogFileNames {
|
||||
var fileName string
|
||||
if filepath.IsAbs(setting.AppDataPath) {
|
||||
fileName = filepath.Join(setting.AppDataPath, dirNameActionLog, actionTask.LogFilename)
|
||||
fileName = filepath.Join(setting.AppDataPath, dirNameActionLog, taskLogFileName)
|
||||
} else {
|
||||
fileName = filepath.Join(setting.AppWorkPath, setting.AppDataPath, dirNameActionLog, actionTask.LogFilename)
|
||||
fileName = filepath.Join(setting.AppWorkPath, setting.AppDataPath, dirNameActionLog, taskLogFileName)
|
||||
}
|
||||
|
||||
if err := os.Remove(fileName); err != nil {
|
||||
|
Loading…
x
Reference in New Issue
Block a user