Skip to content

Commit 965087e

Browse files
author
zsbahtiar
committed
feat: add removeActionTaskLogFilenames
1 parent 1390874 commit 965087e

File tree

1 file changed

+52
-12
lines changed

1 file changed

+52
-12
lines changed

routers/web/repo/actions/actions.go

Lines changed: 52 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ package actions
66
import (
77
"bytes"
88
stdCtx "context"
9+
"golang.org/x/sync/errgroup"
910
"net/http"
11+
"os"
12+
"path/filepath"
1013
"slices"
1114
"strings"
1215

@@ -441,34 +444,71 @@ func DeleteRuns(ctx *context.Context) {
441444
return
442445
}
443446

444-
actionRun, err := actions_model.GetRunsByIDsAndTriggerUserID(ctx, req.ActionIDs, ctx.Doer.ID)
447+
var (
448+
eg = new(errgroup.Group)
449+
actionRuns []*actions_model.ActionRun
450+
actionTasks []*actions_model.ActionTask
451+
jobIDs []int64
452+
)
453+
eg.Go(func() error {
454+
var err error
455+
actionRuns, err = actions_model.GetRunsByIDsAndTriggerUserID(ctx, req.ActionIDs, ctx.Doer.ID)
456+
return err
457+
})
458+
459+
eg.Go(func() error {
460+
actionRunJobs, err := actions_model.GetRunJobsByRunIDs(ctx, req.ActionIDs)
461+
if err != nil {
462+
return err
463+
}
464+
465+
for _, actionRunJob := range actionRunJobs {
466+
jobIDs = append(jobIDs, actionRunJob.ID)
467+
}
468+
actionTasks, err = actions_model.GetRunTasksByJobIDs(ctx, jobIDs)
469+
return err
470+
})
471+
472+
err := eg.Wait()
445473
if err != nil {
446-
ctx.ServerError("failed to get action_run", err)
474+
ctx.ServerError("failed to get action runs and action run jobs", err)
447475
return
448476
}
449477

450-
if len(actionRun) != len(req.ActionIDs) {
478+
if len(actionRuns) != len(req.ActionIDs) {
451479
ctx.ServerError("action ids not match with request", nil)
452480
return
453481
}
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)
462-
}
463482

464483
err = actions_model.DeleteRunByIDs(ctx, req.ActionIDs, jobIDs)
465484
if err != nil {
466485
ctx.ServerError("failed to delete action_run", err)
467486
return
468487
}
488+
489+
removeActionTaskLogFilenames(actionTasks)
490+
469491
ctx.Status(http.StatusNoContent)
470492
}
471493

472494
type DeleteRunsRequest struct {
473495
ActionIDs []int64 `json:"actionIds"`
474496
}
497+
498+
func removeActionTaskLogFilenames(actionTasks []*actions_model.ActionTask) {
499+
dirNameActionLog := "actions_log"
500+
go func() {
501+
for _, actionTask := range actionTasks {
502+
var fileName string
503+
if filepath.IsAbs(setting.AppDataPath) {
504+
fileName = filepath.Join(setting.AppDataPath, dirNameActionLog, actionTask.LogFilename)
505+
} else {
506+
fileName = filepath.Join(setting.AppWorkPath, setting.AppDataPath, dirNameActionLog, actionTask.LogFilename)
507+
}
508+
509+
if err := os.Remove(fileName); err != nil {
510+
log.Error("failed to remove actions_log file %s: %v", fileName, err)
511+
}
512+
}
513+
}()
514+
}

0 commit comments

Comments
 (0)