Skip to content

Commit f989f46

Browse files
authored
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`.
1 parent 81fa471 commit f989f46

File tree

3 files changed

+12
-20
lines changed

3 files changed

+12
-20
lines changed

services/actions/cleanup.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,14 @@ package actions
55

66
import (
77
"context"
8-
"time"
98

109
"code.gitea.io/gitea/models/actions"
1110
"code.gitea.io/gitea/modules/log"
1211
"code.gitea.io/gitea/modules/storage"
1312
)
1413

1514
// Cleanup removes expired actions logs, data and artifacts
16-
func Cleanup(taskCtx context.Context, olderThan time.Duration) error {
15+
func Cleanup(taskCtx context.Context) error {
1716
// TODO: clean up expired actions logs
1817

1918
// clean up expired artifacts

services/cron/tasks_actions.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ func initActionsTasks() {
1919
registerStopEndlessTasks()
2020
registerCancelAbandonedJobs()
2121
registerScheduleTasks()
22+
registerActionsCleanup()
2223
}
2324

2425
func registerStopZombieTasks() {
@@ -63,3 +64,13 @@ func registerScheduleTasks() {
6364
return actions_service.StartScheduleTasks(ctx)
6465
})
6566
}
67+
68+
func registerActionsCleanup() {
69+
RegisterTaskFatal("cleanup_actions", &BaseConfig{
70+
Enabled: true,
71+
RunAtStart: true,
72+
Schedule: "@midnight",
73+
}, func(ctx context.Context, _ *user_model.User, _ Config) error {
74+
return actions_service.Cleanup(ctx)
75+
})
76+
}

services/cron/tasks_basic.go

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313
"code.gitea.io/gitea/models/webhook"
1414
"code.gitea.io/gitea/modules/git"
1515
"code.gitea.io/gitea/modules/setting"
16-
"code.gitea.io/gitea/services/actions"
1716
"code.gitea.io/gitea/services/auth"
1817
"code.gitea.io/gitea/services/migrations"
1918
mirror_service "code.gitea.io/gitea/services/mirror"
@@ -157,20 +156,6 @@ func registerCleanupPackages() {
157156
})
158157
}
159158

160-
func registerActionsCleanup() {
161-
RegisterTaskFatal("cleanup_actions", &OlderThanConfig{
162-
BaseConfig: BaseConfig{
163-
Enabled: true,
164-
RunAtStart: true,
165-
Schedule: "@midnight",
166-
},
167-
OlderThan: 24 * time.Hour,
168-
}, func(ctx context.Context, _ *user_model.User, config Config) error {
169-
realConfig := config.(*OlderThanConfig)
170-
return actions.Cleanup(ctx, realConfig.OlderThan)
171-
})
172-
}
173-
174159
func initBasicTasks() {
175160
if setting.Mirror.Enabled {
176161
registerUpdateMirrorTask()
@@ -187,7 +172,4 @@ func initBasicTasks() {
187172
if setting.Packages.Enabled {
188173
registerCleanupPackages()
189174
}
190-
if setting.Actions.Enabled {
191-
registerActionsCleanup()
192-
}
193175
}

0 commit comments

Comments
 (0)