mirror of
https://github.com/go-gitea/gitea.git
synced 2026-08-24 14:39:52 +00:00
1fa6465efd
Gitea keeps completed Actions runs forever. Artifacts and logs expire on their own schedule, but the run rows never go away, so `action_run` and its child tables grow without bound. Adds `RUN_RETENTION_DAYS` to delete completed runs along with their jobs, tasks and anything the earlier expiries left behind. It defaults to 400 days, matching how long GitHub keeps run history browsable. A dedicated `cleanup_action_runs` cron task performs the cleanup, so admins can schedule it separately from the nightly artifact and log sweep. `0` now means "keep forever" for all three retention settings, where `LOG_RETENTION_DAYS` and `ARTIFACT_RETENTION_DAYS` previously took it literally and deleted everything at the next sweep. Docs: https://gitea.com/gitea/docs/pulls/502 ---- ## ⚠️ BREAKING ⚠️ `RUN_RETENTION_DAYS` defaults to 400, so completed runs older than that are deleted when the cron task next runs at midnight. Set `RUN_RETENTION_DAYS = 0` before upgrading to keep all runs. --------- Co-authored-by: bircni <bircni@icloud.com> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com> Co-authored-by: silverwind <me@silverwind.io>
88 lines
2.4 KiB
Go
88 lines
2.4 KiB
Go
// Copyright 2022 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package cron
|
|
|
|
import (
|
|
"context"
|
|
|
|
user_model "gitea.dev/models/user"
|
|
"gitea.dev/modules/setting"
|
|
actions_service "gitea.dev/services/actions"
|
|
)
|
|
|
|
func initActionsTasks() {
|
|
if !setting.Actions.Enabled {
|
|
return
|
|
}
|
|
registerStopZombieTasks()
|
|
registerStopEndlessTasks()
|
|
registerCancelAbandonedJobs()
|
|
registerScheduleTasks()
|
|
registerActionsCleanup()
|
|
registerCleanupActionRuns()
|
|
}
|
|
|
|
func registerStopZombieTasks() {
|
|
RegisterTaskFatal("stop_zombie_tasks", &BaseConfig{
|
|
Enabled: true,
|
|
RunAtStart: true,
|
|
Schedule: "@every 5m",
|
|
}, func(ctx context.Context, _ *user_model.User, _ *BaseConfig) error {
|
|
return actions_service.StopZombieTasks(ctx)
|
|
})
|
|
}
|
|
|
|
func registerStopEndlessTasks() {
|
|
RegisterTaskFatal("stop_endless_tasks", &BaseConfig{
|
|
Enabled: true,
|
|
RunAtStart: true,
|
|
Schedule: "@every 30m",
|
|
}, func(ctx context.Context, _ *user_model.User, _ *BaseConfig) error {
|
|
return actions_service.StopEndlessTasks(ctx)
|
|
})
|
|
}
|
|
|
|
func registerCancelAbandonedJobs() {
|
|
RegisterTaskFatal("cancel_abandoned_jobs", &BaseConfig{
|
|
Enabled: true,
|
|
RunAtStart: true,
|
|
Schedule: "@every 6h",
|
|
}, func(ctx context.Context, _ *user_model.User, _ *BaseConfig) error {
|
|
return actions_service.CancelAbandonedJobs(ctx)
|
|
})
|
|
}
|
|
|
|
// registerScheduleTasks registers a scheduled task that runs every minute to start any due schedule tasks.
|
|
func registerScheduleTasks() {
|
|
// Register the task with a unique name, enabled status, and schedule for every minute.
|
|
RegisterTaskFatal("start_schedule_tasks", &BaseConfig{
|
|
Enabled: true,
|
|
RunAtStart: false,
|
|
Schedule: "@every 1m",
|
|
}, func(ctx context.Context, _ *user_model.User, _ *BaseConfig) error {
|
|
// Call the function to start schedule tasks and pass the context.
|
|
return actions_service.StartScheduleTasks(ctx)
|
|
})
|
|
}
|
|
|
|
func registerActionsCleanup() {
|
|
RegisterTaskFatal("cleanup_actions", &BaseConfig{
|
|
Enabled: true,
|
|
RunAtStart: false,
|
|
Schedule: "@midnight",
|
|
}, func(ctx context.Context, _ *user_model.User, _ *BaseConfig) error {
|
|
return actions_service.Cleanup(ctx)
|
|
})
|
|
}
|
|
|
|
func registerCleanupActionRuns() {
|
|
RegisterTaskFatal("cleanup_action_runs", &BaseConfig{
|
|
Enabled: true,
|
|
RunAtStart: false,
|
|
Schedule: "@midnight",
|
|
}, func(ctx context.Context, _ *user_model.User, _ *BaseConfig) error {
|
|
return actions_service.CleanupOldRuns(ctx)
|
|
})
|
|
}
|