diff options
author | Jason Song <i@wolfogre.com> | 2024-07-30 10:27:28 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-07-30 10:27:28 +0800 |
commit | f989f464386139592b6911cad1be4c901eb97fe5 (patch) | |
tree | cbc037b6453e900f538405f3e2967ad4fd9d14d8 | |
parent | 81fa471119a6733d257f63f8c2c1f4acc583d21b (diff) | |
download | gitea-f989f464386139592b6911cad1be4c901eb97fe5.tar.gz gitea-f989f464386139592b6911cad1be4c901eb97fe5.zip |
Move `registerActionsCleanup` to `initActionsTasks` (#31721)
There's already `initActionsTasks`; it will avoid additional check for
if Actions enabled to move `registerActionsCleanup` into it.
And we don't really need `OlderThanConfig`.
-rw-r--r-- | services/actions/cleanup.go | 3 | ||||
-rw-r--r-- | services/cron/tasks_actions.go | 11 | ||||
-rw-r--r-- | services/cron/tasks_basic.go | 18 |
3 files changed, 12 insertions, 20 deletions
diff --git a/services/actions/cleanup.go b/services/actions/cleanup.go index 5376c2624c..6ccc8dd198 100644 --- a/services/actions/cleanup.go +++ b/services/actions/cleanup.go @@ -5,7 +5,6 @@ package actions import ( "context" - "time" "code.gitea.io/gitea/models/actions" "code.gitea.io/gitea/modules/log" @@ -13,7 +12,7 @@ import ( ) // Cleanup removes expired actions logs, data and artifacts -func Cleanup(taskCtx context.Context, olderThan time.Duration) error { +func Cleanup(taskCtx context.Context) error { // TODO: clean up expired actions logs // clean up expired artifacts diff --git a/services/cron/tasks_actions.go b/services/cron/tasks_actions.go index 0875792503..9b5e0b9f41 100644 --- a/services/cron/tasks_actions.go +++ b/services/cron/tasks_actions.go @@ -19,6 +19,7 @@ func initActionsTasks() { registerStopEndlessTasks() registerCancelAbandonedJobs() registerScheduleTasks() + registerActionsCleanup() } func registerStopZombieTasks() { @@ -63,3 +64,13 @@ func registerScheduleTasks() { return actions_service.StartScheduleTasks(ctx) }) } + +func registerActionsCleanup() { + RegisterTaskFatal("cleanup_actions", &BaseConfig{ + Enabled: true, + RunAtStart: true, + Schedule: "@midnight", + }, func(ctx context.Context, _ *user_model.User, _ Config) error { + return actions_service.Cleanup(ctx) + }) +} diff --git a/services/cron/tasks_basic.go b/services/cron/tasks_basic.go index 3869382d22..2a213ae515 100644 --- a/services/cron/tasks_basic.go +++ b/services/cron/tasks_basic.go @@ -13,7 +13,6 @@ import ( "code.gitea.io/gitea/models/webhook" "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/setting" - "code.gitea.io/gitea/services/actions" "code.gitea.io/gitea/services/auth" "code.gitea.io/gitea/services/migrations" mirror_service "code.gitea.io/gitea/services/mirror" @@ -157,20 +156,6 @@ func registerCleanupPackages() { }) } -func registerActionsCleanup() { - RegisterTaskFatal("cleanup_actions", &OlderThanConfig{ - BaseConfig: BaseConfig{ - Enabled: true, - RunAtStart: true, - Schedule: "@midnight", - }, - OlderThan: 24 * time.Hour, - }, func(ctx context.Context, _ *user_model.User, config Config) error { - realConfig := config.(*OlderThanConfig) - return actions.Cleanup(ctx, realConfig.OlderThan) - }) -} - func initBasicTasks() { if setting.Mirror.Enabled { registerUpdateMirrorTask() @@ -187,7 +172,4 @@ func initBasicTasks() { if setting.Packages.Enabled { registerCleanupPackages() } - if setting.Actions.Enabled { - registerActionsCleanup() - } } |