aboutsummaryrefslogtreecommitdiffstats
path: root/services
diff options
context:
space:
mode:
Diffstat (limited to 'services')
-rw-r--r--services/cron/tasks_basic.go2
-rw-r--r--services/packages/cleanup/cleanup.go26
2 files changed, 23 insertions, 5 deletions
diff --git a/services/cron/tasks_basic.go b/services/cron/tasks_basic.go
index 2e6560ec0c..2a213ae515 100644
--- a/services/cron/tasks_basic.go
+++ b/services/cron/tasks_basic.go
@@ -152,7 +152,7 @@ func registerCleanupPackages() {
OlderThan: 24 * time.Hour,
}, func(ctx context.Context, _ *user_model.User, config Config) error {
realConfig := config.(*OlderThanConfig)
- return packages_cleanup_service.Cleanup(ctx, realConfig.OlderThan)
+ return packages_cleanup_service.CleanupTask(ctx, realConfig.OlderThan)
})
}
diff --git a/services/packages/cleanup/cleanup.go b/services/packages/cleanup/cleanup.go
index 43fbc1ad9b..77bcfb1942 100644
--- a/services/packages/cleanup/cleanup.go
+++ b/services/packages/cleanup/cleanup.go
@@ -20,9 +20,17 @@ import (
debian_service "code.gitea.io/gitea/services/packages/debian"
)
-// Cleanup removes expired package data
-func Cleanup(taskCtx context.Context, olderThan time.Duration) error {
- ctx, committer, err := db.TxContext(taskCtx)
+// Task method to execute cleanup rules and cleanup expired package data
+func CleanupTask(ctx context.Context, olderThan time.Duration) error {
+ if err := ExecuteCleanupRules(ctx); err != nil {
+ return err
+ }
+
+ return CleanupExpiredData(ctx, olderThan)
+}
+
+func ExecuteCleanupRules(outerCtx context.Context) error {
+ ctx, committer, err := db.TxContext(outerCtx)
if err != nil {
return err
}
@@ -30,7 +38,7 @@ func Cleanup(taskCtx context.Context, olderThan time.Duration) error {
err = packages_model.IterateEnabledCleanupRules(ctx, func(ctx context.Context, pcr *packages_model.PackageCleanupRule) error {
select {
- case <-taskCtx.Done():
+ case <-outerCtx.Done():
return db.ErrCancelledf("While processing package cleanup rules")
default:
}
@@ -122,6 +130,16 @@ func Cleanup(taskCtx context.Context, olderThan time.Duration) error {
return err
}
+ return committer.Commit()
+}
+
+func CleanupExpiredData(outerCtx context.Context, olderThan time.Duration) error {
+ ctx, committer, err := db.TxContext(outerCtx)
+ if err != nil {
+ return err
+ }
+ defer committer.Close()
+
if err := container_service.Cleanup(ctx, olderThan); err != nil {
return err
}