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`.
This commit is contained in:
Jason Song 2024-07-30 10:27:28 +08:00 committed by GitHub
parent 81fa471119
commit f989f46438
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 12 additions and 20 deletions

View File

@ -5,7 +5,6 @@ package actions
import ( import (
"context" "context"
"time"
"code.gitea.io/gitea/models/actions" "code.gitea.io/gitea/models/actions"
"code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/log"
@ -13,7 +12,7 @@ import (
) )
// Cleanup removes expired actions logs, data and artifacts // 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 // TODO: clean up expired actions logs
// clean up expired artifacts // clean up expired artifacts

View File

@ -19,6 +19,7 @@ func initActionsTasks() {
registerStopEndlessTasks() registerStopEndlessTasks()
registerCancelAbandonedJobs() registerCancelAbandonedJobs()
registerScheduleTasks() registerScheduleTasks()
registerActionsCleanup()
} }
func registerStopZombieTasks() { func registerStopZombieTasks() {
@ -63,3 +64,13 @@ func registerScheduleTasks() {
return actions_service.StartScheduleTasks(ctx) 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)
})
}

View File

@ -13,7 +13,6 @@ import (
"code.gitea.io/gitea/models/webhook" "code.gitea.io/gitea/models/webhook"
"code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/services/actions"
"code.gitea.io/gitea/services/auth" "code.gitea.io/gitea/services/auth"
"code.gitea.io/gitea/services/migrations" "code.gitea.io/gitea/services/migrations"
mirror_service "code.gitea.io/gitea/services/mirror" 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() { func initBasicTasks() {
if setting.Mirror.Enabled { if setting.Mirror.Enabled {
registerUpdateMirrorTask() registerUpdateMirrorTask()
@ -187,7 +172,4 @@ func initBasicTasks() {
if setting.Packages.Enabled { if setting.Packages.Enabled {
registerCleanupPackages() registerCleanupPackages()
} }
if setting.Actions.Enabled {
registerActionsCleanup()
}
} }