From 621c6f6fab2f2ce6f98f16eefb62c79a2f73ae35 Mon Sep 17 00:00:00 2001 From: Jason Song Date: Tue, 30 Jul 2024 12:11:45 +0800 Subject: [PATCH 01/15] feat: clear up logs --- models/actions/task.go | 18 ++++++++-- modules/setting/actions.go | 12 +++++-- services/actions/cleanup.go | 69 +++++++++++++++++++++++++++++++------ 3 files changed, 83 insertions(+), 16 deletions(-) diff --git a/models/actions/task.go b/models/actions/task.go index f2f796a626f8d..61055987e3f99 100644 --- a/models/actions/task.go +++ b/models/actions/task.go @@ -35,7 +35,7 @@ type ActionTask struct { RunnerID int64 `xorm:"index"` Status Status `xorm:"index"` Started timeutil.TimeStamp `xorm:"index"` - Stopped timeutil.TimeStamp + Stopped timeutil.TimeStamp `xorm:"index(stopped_log_expired)"` RepoID int64 `xorm:"index"` OwnerID int64 `xorm:"index"` @@ -51,8 +51,8 @@ type ActionTask struct { LogInStorage bool // read log from database or from storage LogLength int64 // lines count LogSize int64 // blob size - LogIndexes LogIndexes `xorm:"LONGBLOB"` // line number to offset - LogExpired bool // files that are too old will be deleted + LogIndexes LogIndexes `xorm:"LONGBLOB"` // line number to offset + LogExpired bool `xorm:"index(stopped_log_expired)"` // files that are too old will be deleted Created timeutil.TimeStamp `xorm:"created"` Updated timeutil.TimeStamp `xorm:"updated index"` @@ -470,6 +470,18 @@ func StopTask(ctx context.Context, taskID int64, status Status) error { return nil } +func IterateOldTasks(ctx context.Context, before timeutil.TimeStamp, f func(ctx context.Context, task *ActionTask) error) error { + e := db.GetEngine(ctx) + + return e.Where("stopped > 0 AND stopped < ? AND log_expired = false", before).Iterate(&ActionTask{}, func(_ int, bean interface{}) error { + task := bean.(*ActionTask) + if ctx.Err() != nil { + return ctx.Err() + } + return f(ctx, task) + }) +} + func isSubset(set, subset []string) bool { m := make(container.Set[string], len(set)) for _, v := range set { diff --git a/modules/setting/actions.go b/modules/setting/actions.go index 9fd484c3b804e..2581c8f944f17 100644 --- a/modules/setting/actions.go +++ b/modules/setting/actions.go @@ -14,10 +14,11 @@ import ( // Actions settings var ( Actions = struct { - LogStorage *Storage // how the created logs should be stored - ArtifactStorage *Storage // how the created artifacts should be stored - ArtifactRetentionDays int64 `ini:"ARTIFACT_RETENTION_DAYS"` Enabled bool + LogStorage *Storage // how the created logs should be stored + LogRetentionDays int64 `ini:"LOG_RETENTION_DAYS"` + ArtifactStorage *Storage // how the created artifacts should be stored + ArtifactRetentionDays int64 `ini:"ARTIFACT_RETENTION_DAYS"` DefaultActionsURL defaultActionsURL `ini:"DEFAULT_ACTIONS_URL"` ZombieTaskTimeout time.Duration `ini:"ZOMBIE_TASK_TIMEOUT"` EndlessTaskTimeout time.Duration `ini:"ENDLESS_TASK_TIMEOUT"` @@ -92,5 +93,10 @@ func loadActionsFrom(rootCfg ConfigProvider) error { Actions.EndlessTaskTimeout = sec.Key("ENDLESS_TASK_TIMEOUT").MustDuration(3 * time.Hour) Actions.AbandonedJobTimeout = sec.Key("ABANDONED_JOB_TIMEOUT").MustDuration(24 * time.Hour) + // default to 1 year + if Actions.LogRetentionDays <= 0 { + Actions.LogRetentionDays = 365 + } + return err } diff --git a/services/actions/cleanup.go b/services/actions/cleanup.go index 6ccc8dd19898a..463f35792ae06 100644 --- a/services/actions/cleanup.go +++ b/services/actions/cleanup.go @@ -5,18 +5,31 @@ package actions import ( "context" + "errors" + "fmt" + "time" - "code.gitea.io/gitea/models/actions" + actions_model "code.gitea.io/gitea/models/actions" + actions_module "code.gitea.io/gitea/modules/actions" "code.gitea.io/gitea/modules/log" + "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/storage" + "code.gitea.io/gitea/modules/timeutil" ) // Cleanup removes expired actions logs, data and artifacts -func Cleanup(taskCtx context.Context) error { - // TODO: clean up expired actions logs - +func Cleanup(ctx context.Context) error { // clean up expired artifacts - return CleanupArtifacts(taskCtx) + if err := CleanupArtifacts(ctx); err != nil { + return fmt.Errorf("cleanup artifacts: %w", err) + } + + // clean up old logs + if err := CleanupLogs(ctx); err != nil { + return fmt.Errorf("cleanup logs: %w", err) + } + + return nil } // CleanupArtifacts removes expired add need-deleted artifacts and set records expired status @@ -28,13 +41,13 @@ func CleanupArtifacts(taskCtx context.Context) error { } func cleanExpiredArtifacts(taskCtx context.Context) error { - artifacts, err := actions.ListNeedExpiredArtifacts(taskCtx) + artifacts, err := actions_model.ListNeedExpiredArtifacts(taskCtx) if err != nil { return err } - log.Info("Found %d expired artifacts", len(artifacts)) + log.Info("Found ∂%d expired artifacts", len(artifacts)) for _, artifact := range artifacts { - if err := actions.SetArtifactExpired(taskCtx, artifact.ID); err != nil { + if err := actions_model.SetArtifactExpired(taskCtx, artifact.ID); err != nil { log.Error("Cannot set artifact %d expired: %v", artifact.ID, err) continue } @@ -52,13 +65,13 @@ const deleteArtifactBatchSize = 100 func cleanNeedDeleteArtifacts(taskCtx context.Context) error { for { - artifacts, err := actions.ListPendingDeleteArtifacts(taskCtx, deleteArtifactBatchSize) + artifacts, err := actions_model.ListPendingDeleteArtifacts(taskCtx, deleteArtifactBatchSize) if err != nil { return err } log.Info("Found %d artifacts pending deletion", len(artifacts)) for _, artifact := range artifacts { - if err := actions.SetArtifactDeleted(taskCtx, artifact.ID); err != nil { + if err := actions_model.SetArtifactDeleted(taskCtx, artifact.ID); err != nil { log.Error("Cannot set artifact %d deleted: %v", artifact.ID, err) continue } @@ -75,3 +88,39 @@ func cleanNeedDeleteArtifacts(taskCtx context.Context) error { } return nil } + +// CleanupLogs removes logs which are older than the configured retention time +func CleanupLogs(ctx context.Context) error { + before := timeutil.TimeStampNow().AddDuration(-time.Duration(setting.Actions.LogRetentionDays) * 24 * time.Hour) + + count := 0 + if err := actions_model.IterateOldTasks(ctx, before, func(ctx context.Context, task *actions_model.ActionTask) error { + err := actions_module.RemoveLogs(ctx, task.LogInStorage, task.LogFilename) + if err != nil { + log.Error("Failed to remove log %s (in storage %v) of task %v: %v", task.LogFilename, task.LogInStorage, task.ID, err) + // do not return error here, continue to next task + return nil + } + + task.LogIndexes = nil // clear log indexes since it's a heavy field + task.LogExpired = true + if err := actions_model.UpdateTask(ctx, task, "log_indexes", "log_expired"); err != nil { + log.Warn("Failed to update task %v: %v", task.ID, err) + // do not return error here, continue to next task + return nil + } + + log.Trace("Removed log %s of task %v", task.LogFilename, task.ID) + count++ + + return nil + }); err != nil { + if errors.Is(err, ctx.Err()) { + return nil + } + return fmt.Errorf("iterate old tasks: %w", err) + } + + log.Info("Removed %d logs", count) + return nil +} From e01c7531ea5452c52528462cecd301c442b2f8a8 Mon Sep 17 00:00:00 2001 From: Jason Song Date: Tue, 30 Jul 2024 12:20:20 +0800 Subject: [PATCH 02/15] feat: show expired log --- routers/web/repo/actions/view.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/routers/web/repo/actions/view.go b/routers/web/repo/actions/view.go index 2c62c8d9ec0fa..aaf6a48d6b2ac 100644 --- a/routers/web/repo/actions/view.go +++ b/routers/web/repo/actions/view.go @@ -222,6 +222,24 @@ func ViewPost(ctx *context_module.Context) { step := steps[cursor.Step] + // if task log is expired, return a consistent log line + if task.LogExpired { + if cursor.Cursor == 0 { + resp.Logs.StepsLog = append(resp.Logs.StepsLog, &ViewStepLog{ + Step: cursor.Step, + Cursor: 1, + Lines: []*ViewStepLogLine{ + { + Index: 1, + Message: "TODO: logs have been cleaned up", + Timestamp: float64(time.Now().UnixNano()) / float64(time.Second), + }, + }, + Started: int64(step.Started), + }) + } + } + logLines := make([]*ViewStepLogLine, 0) // marshal to '[]' instead fo 'null' in json index := step.LogIndex + cursor.Cursor From 8b34f4a1219f251969cc8724b1acbfc539e5ef18 Mon Sep 17 00:00:00 2001 From: Jason Song Date: Tue, 30 Jul 2024 14:07:42 +0800 Subject: [PATCH 03/15] fix: FindOldTasksToExpire --- models/actions/task.go | 13 +++++------ services/actions/cleanup.go | 44 ++++++++++++++++++------------------- 2 files changed, 27 insertions(+), 30 deletions(-) diff --git a/models/actions/task.go b/models/actions/task.go index 61055987e3f99..1ed79d81c54ed 100644 --- a/models/actions/task.go +++ b/models/actions/task.go @@ -470,16 +470,13 @@ func StopTask(ctx context.Context, taskID int64, status Status) error { return nil } -func IterateOldTasks(ctx context.Context, before timeutil.TimeStamp, f func(ctx context.Context, task *ActionTask) error) error { +func FindOldTasksToExpire(ctx context.Context, oldThan timeutil.TimeStamp, limit int) ([]*ActionTask, error) { e := db.GetEngine(ctx) - return e.Where("stopped > 0 AND stopped < ? AND log_expired = false", before).Iterate(&ActionTask{}, func(_ int, bean interface{}) error { - task := bean.(*ActionTask) - if ctx.Err() != nil { - return ctx.Err() - } - return f(ctx, task) - }) + tasks := make([]*ActionTask, 0, limit) + return tasks, e.Where("stopped > 0 AND stopped < ? AND log_expired = false", oldThan). + Limit(limit). + Find(&tasks) } func isSubset(set, subset []string) bool { diff --git a/services/actions/cleanup.go b/services/actions/cleanup.go index 463f35792ae06..998712f0f88e9 100644 --- a/services/actions/cleanup.go +++ b/services/actions/cleanup.go @@ -5,7 +5,6 @@ package actions import ( "context" - "errors" "fmt" "time" @@ -89,36 +88,37 @@ func cleanNeedDeleteArtifacts(taskCtx context.Context) error { return nil } +const deleteLogBatchSize = 100 + // CleanupLogs removes logs which are older than the configured retention time func CleanupLogs(ctx context.Context) error { before := timeutil.TimeStampNow().AddDuration(-time.Duration(setting.Actions.LogRetentionDays) * 24 * time.Hour) count := 0 - if err := actions_model.IterateOldTasks(ctx, before, func(ctx context.Context, task *actions_model.ActionTask) error { - err := actions_module.RemoveLogs(ctx, task.LogInStorage, task.LogFilename) + for { + tasks, err := actions_model.FindOldTasksToExpire(ctx, before, deleteLogBatchSize) if err != nil { - log.Error("Failed to remove log %s (in storage %v) of task %v: %v", task.LogFilename, task.LogInStorage, task.ID, err) - // do not return error here, continue to next task - return nil + return fmt.Errorf("find old tasks: %w", err) } - - task.LogIndexes = nil // clear log indexes since it's a heavy field - task.LogExpired = true - if err := actions_model.UpdateTask(ctx, task, "log_indexes", "log_expired"); err != nil { - log.Warn("Failed to update task %v: %v", task.ID, err) - // do not return error here, continue to next task - return nil + for _, task := range tasks { + if err := actions_module.RemoveLogs(ctx, task.LogInStorage, task.LogFilename); err != nil { + log.Error("Failed to remove log %s (in storage %v) of task %v: %v", task.LogFilename, task.LogInStorage, task.ID, err) + // do not return error here, continue to next task + continue + } + task.LogIndexes = nil // clear log indexes since it's a heavy field + task.LogExpired = true + if err := actions_model.UpdateTask(ctx, task, "log_indexes", "log_expired"); err != nil { + log.Error("Failed to update task %v: %v", task.ID, err) + // do not return error here, continue to next task + continue + } + count++ + log.Trace("Removed log %s of task %v", task.LogFilename, task.ID) } - - log.Trace("Removed log %s of task %v", task.LogFilename, task.ID) - count++ - - return nil - }); err != nil { - if errors.Is(err, ctx.Err()) { - return nil + if len(tasks) < deleteLogBatchSize { + break } - return fmt.Errorf("iterate old tasks: %w", err) } log.Info("Removed %d logs", count) From 95ef9c382e45696bd5b9ac0081c518cd8ad7f4c8 Mon Sep 17 00:00:00 2001 From: Jason Song Date: Tue, 30 Jul 2024 14:39:26 +0800 Subject: [PATCH 04/15] chore: log message --- options/locale/locale_en-US.ini | 1 + routers/web/repo/actions/view.go | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 53d746ef1256c..b187ec4746369 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -3679,6 +3679,7 @@ runs.no_workflows.quick_start = Don't know how to start with Gitea Actions? See runs.no_workflows.documentation = For more information on Gitea Actions, see the documentation. runs.no_runs = The workflow has no runs yet. runs.empty_commit_message = (empty commit message) +runs.expire_log_message = Logs have been cleaned up because they were too old. You can configure LOG_RETENTION_DAYS to retain logs for a longer duration. workflow.disable = Disable Workflow workflow.disable_success = Workflow '%s' disabled successfully. diff --git a/routers/web/repo/actions/view.go b/routers/web/repo/actions/view.go index aaf6a48d6b2ac..502e3c62d6658 100644 --- a/routers/web/repo/actions/view.go +++ b/routers/web/repo/actions/view.go @@ -231,13 +231,14 @@ func ViewPost(ctx *context_module.Context) { Lines: []*ViewStepLogLine{ { Index: 1, - Message: "TODO: logs have been cleaned up", + Message: ctx.Locale.TrString("actions.runs.expire_log_message"), Timestamp: float64(time.Now().UnixNano()) / float64(time.Second), }, }, Started: int64(step.Started), }) } + continue } logLines := make([]*ViewStepLogLine, 0) // marshal to '[]' instead fo 'null' in json From 604f7bcf88c6e3251143d150b760ce41c896e878 Mon Sep 17 00:00:00 2001 From: Jason Song Date: Tue, 30 Jul 2024 14:44:46 +0800 Subject: [PATCH 05/15] chore: fix typo --- services/actions/cleanup.go | 2 +- services/cron/tasks_actions.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/services/actions/cleanup.go b/services/actions/cleanup.go index 998712f0f88e9..ec669ec384bb5 100644 --- a/services/actions/cleanup.go +++ b/services/actions/cleanup.go @@ -44,7 +44,7 @@ func cleanExpiredArtifacts(taskCtx context.Context) error { if err != nil { return err } - log.Info("Found ∂%d expired artifacts", len(artifacts)) + log.Info("Found %d expired artifacts", len(artifacts)) for _, artifact := range artifacts { if err := actions_model.SetArtifactExpired(taskCtx, artifact.ID); err != nil { log.Error("Cannot set artifact %d expired: %v", artifact.ID, err) diff --git a/services/cron/tasks_actions.go b/services/cron/tasks_actions.go index 9b5e0b9f415bd..59cfe36d14fe7 100644 --- a/services/cron/tasks_actions.go +++ b/services/cron/tasks_actions.go @@ -68,7 +68,7 @@ func registerScheduleTasks() { func registerActionsCleanup() { RegisterTaskFatal("cleanup_actions", &BaseConfig{ Enabled: true, - RunAtStart: true, + RunAtStart: false, Schedule: "@midnight", }, func(ctx context.Context, _ *user_model.User, _ Config) error { return actions_service.Cleanup(ctx) From 8d4e25b78addaae4950a22e5e92aca3e0293eb0e Mon Sep 17 00:00:00 2001 From: Jason Song Date: Tue, 30 Jul 2024 14:47:34 +0800 Subject: [PATCH 06/15] chore: example ini --- custom/conf/app.example.ini | 2 ++ 1 file changed, 2 insertions(+) diff --git a/custom/conf/app.example.ini b/custom/conf/app.example.ini index c29d2e5be43ee..89d04d381cd43 100644 --- a/custom/conf/app.example.ini +++ b/custom/conf/app.example.ini @@ -2684,6 +2684,8 @@ LEVEL = Info ;; ;; Default platform to get action plugins, `github` for `https://github.com`, `self` for the current Gitea instance. ;DEFAULT_ACTIONS_URL = github +;; Logs retention time in days. Old logs will be deleted after this period. +;LOG_RETENTION_DAYS = 365 ;; Default artifact retention time in days. Artifacts could have their own retention periods by setting the `retention-days` option in `actions/upload-artifact` step. ;ARTIFACT_RETENTION_DAYS = 90 ;; Timeout to stop the task which have running status, but haven't been updated for a long time From dc0018913ca25d616be1fb7531875d8fa3470f00 Mon Sep 17 00:00:00 2001 From: Jason Song Date: Tue, 30 Jul 2024 15:39:08 +0800 Subject: [PATCH 07/15] feat: migration --- models/migrations/migrations.go | 2 ++ models/migrations/v1_23/v302.go | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 models/migrations/v1_23/v302.go diff --git a/models/migrations/migrations.go b/models/migrations/migrations.go index 0e13e89f009da..a57b4da031212 100644 --- a/models/migrations/migrations.go +++ b/models/migrations/migrations.go @@ -595,6 +595,8 @@ var migrations = []Migration{ NewMigration("Add force-push branch protection support", v1_23.AddForcePushBranchProtection), // v301 -> v302 NewMigration("Add skip_secondary_authorization option to oauth2 application table", v1_23.AddSkipSecondaryAuthColumnToOAuth2ApplicationTable), + // v302 -> v303 + NewMigration("Add index to action_task stopped log_expired", v1_23.AddIndexToActionTaskStoppedLogExpired), } // GetCurrentDBVersion returns the current db version diff --git a/models/migrations/v1_23/v302.go b/models/migrations/v1_23/v302.go new file mode 100644 index 0000000000000..d7ea03eb3da93 --- /dev/null +++ b/models/migrations/v1_23/v302.go @@ -0,0 +1,18 @@ +// Copyright 2024 The Gitea Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +package v1_23 //nolint + +import ( + "code.gitea.io/gitea/modules/timeutil" + + "xorm.io/xorm" +) + +func AddIndexToActionTaskStoppedLogExpired(x *xorm.Engine) error { + type ActionTask struct { + Stopped timeutil.TimeStamp `xorm:"index(stopped_log_expired)"` + LogExpired bool `xorm:"index(stopped_log_expired)"` + } + return x.Sync(new(ActionTask)) +} From d591a89fd620ddc682fff485aafab9ad69e99aa6 Mon Sep 17 00:00:00 2001 From: Jason Song Date: Tue, 30 Jul 2024 15:43:04 +0800 Subject: [PATCH 08/15] chore: improve settings --- modules/setting/actions.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/modules/setting/actions.go b/modules/setting/actions.go index 2581c8f944f17..f4072d13f4553 100644 --- a/modules/setting/actions.go +++ b/modules/setting/actions.go @@ -79,10 +79,17 @@ func loadActionsFrom(rootCfg ConfigProvider) error { if err != nil { return err } + // default to 1 year + if Actions.LogRetentionDays <= 0 { + Actions.LogRetentionDays = 365 + } actionsSec, _ := rootCfg.GetSection("actions.artifacts") Actions.ArtifactStorage, err = getStorage(rootCfg, "actions_artifacts", "", actionsSec) + if err != nil { + return err + } // default to 90 days in Github Actions if Actions.ArtifactRetentionDays <= 0 { @@ -93,10 +100,5 @@ func loadActionsFrom(rootCfg ConfigProvider) error { Actions.EndlessTaskTimeout = sec.Key("ENDLESS_TASK_TIMEOUT").MustDuration(3 * time.Hour) Actions.AbandonedJobTimeout = sec.Key("ABANDONED_JOB_TIMEOUT").MustDuration(24 * time.Hour) - // default to 1 year - if Actions.LogRetentionDays <= 0 { - Actions.LogRetentionDays = 365 - } - - return err + return nil } From dc929dd0d5d24aa83d94e6a8b98bee52d6e47375 Mon Sep 17 00:00:00 2001 From: Jason Song Date: Tue, 30 Jul 2024 15:44:11 +0800 Subject: [PATCH 09/15] chore: add comment --- models/actions/task.go | 1 + 1 file changed, 1 insertion(+) diff --git a/models/actions/task.go b/models/actions/task.go index 1ed79d81c54ed..dcf52126ecadc 100644 --- a/models/actions/task.go +++ b/models/actions/task.go @@ -474,6 +474,7 @@ func FindOldTasksToExpire(ctx context.Context, oldThan timeutil.TimeStamp, limit e := db.GetEngine(ctx) tasks := make([]*ActionTask, 0, limit) + // Check "stopped > 0" to avoid deleting tasks that are still running return tasks, e.Where("stopped > 0 AND stopped < ? AND log_expired = false", oldThan). Limit(limit). Find(&tasks) From 18a990f0f33f4e77a6e692bd8992b94dd4cbcc7a Mon Sep 17 00:00:00 2001 From: Jason Song Date: Tue, 30 Jul 2024 15:46:58 +0800 Subject: [PATCH 10/15] chore: olderThan --- models/actions/task.go | 4 ++-- services/actions/cleanup.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/models/actions/task.go b/models/actions/task.go index dcf52126ecadc..ad07aeab5259c 100644 --- a/models/actions/task.go +++ b/models/actions/task.go @@ -470,12 +470,12 @@ func StopTask(ctx context.Context, taskID int64, status Status) error { return nil } -func FindOldTasksToExpire(ctx context.Context, oldThan timeutil.TimeStamp, limit int) ([]*ActionTask, error) { +func FindOldTasksToExpire(ctx context.Context, olderThan timeutil.TimeStamp, limit int) ([]*ActionTask, error) { e := db.GetEngine(ctx) tasks := make([]*ActionTask, 0, limit) // Check "stopped > 0" to avoid deleting tasks that are still running - return tasks, e.Where("stopped > 0 AND stopped < ? AND log_expired = false", oldThan). + return tasks, e.Where("stopped > 0 AND stopped < ? AND log_expired = false", olderThan). Limit(limit). Find(&tasks) } diff --git a/services/actions/cleanup.go b/services/actions/cleanup.go index ec669ec384bb5..1223ebcab6349 100644 --- a/services/actions/cleanup.go +++ b/services/actions/cleanup.go @@ -92,11 +92,11 @@ const deleteLogBatchSize = 100 // CleanupLogs removes logs which are older than the configured retention time func CleanupLogs(ctx context.Context) error { - before := timeutil.TimeStampNow().AddDuration(-time.Duration(setting.Actions.LogRetentionDays) * 24 * time.Hour) + olderThan := timeutil.TimeStampNow().AddDuration(-time.Duration(setting.Actions.LogRetentionDays) * 24 * time.Hour) count := 0 for { - tasks, err := actions_model.FindOldTasksToExpire(ctx, before, deleteLogBatchSize) + tasks, err := actions_model.FindOldTasksToExpire(ctx, olderThan, deleteLogBatchSize) if err != nil { return fmt.Errorf("find old tasks: %w", err) } From 492ed6fdc0fd3f3b2b8a7b20def8478a0cb1f943 Mon Sep 17 00:00:00 2001 From: Jason Song Date: Wed, 31 Jul 2024 10:32:38 +0800 Subject: [PATCH 11/15] Update models/actions/task.go --- models/actions/task.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/actions/task.go b/models/actions/task.go index ad07aeab5259c..856a43af4a9a9 100644 --- a/models/actions/task.go +++ b/models/actions/task.go @@ -475,7 +475,7 @@ func FindOldTasksToExpire(ctx context.Context, olderThan timeutil.TimeStamp, lim tasks := make([]*ActionTask, 0, limit) // Check "stopped > 0" to avoid deleting tasks that are still running - return tasks, e.Where("stopped > 0 AND stopped < ? AND log_expired = false", olderThan). + return tasks, e.Where("stopped > 0 AND stopped < ? AND log_expired = ?", olderThan, false). Limit(limit). Find(&tasks) } From 53085c9a37263ffb4e576dcec590356eb474089c Mon Sep 17 00:00:00 2001 From: Jason Song Date: Wed, 31 Jul 2024 10:46:03 +0800 Subject: [PATCH 12/15] chore: set Timestamp --- routers/web/repo/actions/view.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/routers/web/repo/actions/view.go b/routers/web/repo/actions/view.go index 502e3c62d6658..84319fc8609bb 100644 --- a/routers/web/repo/actions/view.go +++ b/routers/web/repo/actions/view.go @@ -230,9 +230,11 @@ func ViewPost(ctx *context_module.Context) { Cursor: 1, Lines: []*ViewStepLogLine{ { - Index: 1, - Message: ctx.Locale.TrString("actions.runs.expire_log_message"), - Timestamp: float64(time.Now().UnixNano()) / float64(time.Second), + Index: 1, + Message: ctx.Locale.TrString("actions.runs.expire_log_message"), + // Timestamp doesn't mean anything when the log is expired. + // Set it to the task's updated time since it's probably the time when the log has expired. + Timestamp: float64(task.Updated.AsTime().UnixNano()) / float64(time.Second), }, }, Started: int64(step.Started), From 8d50ccbd993d2e8b0ff3af5fbd22d35a52ca6dcf Mon Sep 17 00:00:00 2001 From: Jason Song Date: Thu, 1 Aug 2024 10:13:29 +0800 Subject: [PATCH 13/15] Update options/locale/locale_en-US.ini Co-authored-by: silverwind --- options/locale/locale_en-US.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 88c81b60caa4c..523720610b6ec 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -3679,7 +3679,7 @@ runs.no_workflows.quick_start = Don't know how to start with Gitea Actions? See runs.no_workflows.documentation = For more information on Gitea Actions, see the documentation. runs.no_runs = The workflow has no runs yet. runs.empty_commit_message = (empty commit message) -runs.expire_log_message = Logs have been cleaned up because they were too old. You can configure LOG_RETENTION_DAYS to retain logs for a longer duration. +runs.expire_log_message = Logs have been purged because they were too old. You can configure LOG_RETENTION_DAYS to retain logs for a longer duration. workflow.disable = Disable Workflow workflow.disable_success = Workflow '%s' disabled successfully. From 4e0d576d5a442854a71f0af6b1d7c91a82204ba1 Mon Sep 17 00:00:00 2001 From: Jason Song Date: Thu, 1 Aug 2024 10:20:48 +0800 Subject: [PATCH 14/15] Update options/locale/locale_en-US.ini Co-authored-by: Lunny Xiao --- options/locale/locale_en-US.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 523720610b6ec..03d8ac415ec34 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -3679,7 +3679,7 @@ runs.no_workflows.quick_start = Don't know how to start with Gitea Actions? See runs.no_workflows.documentation = For more information on Gitea Actions, see the documentation. runs.no_runs = The workflow has no runs yet. runs.empty_commit_message = (empty commit message) -runs.expire_log_message = Logs have been purged because they were too old. You can configure LOG_RETENTION_DAYS to retain logs for a longer duration. +runs.expire_log_message = Logs have been purged because they were too old. Site administrator can configure LOG_RETENTION_DAYS to retain logs for a longer duration. workflow.disable = Disable Workflow workflow.disable_success = Workflow '%s' disabled successfully. From 7af79e1caa12c9a8bcb0f888cad34d963f55b34d Mon Sep 17 00:00:00 2001 From: Jason Song Date: Thu, 1 Aug 2024 16:32:54 +0800 Subject: [PATCH 15/15] Update options/locale/locale_en-US.ini --- options/locale/locale_en-US.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 03d8ac415ec34..05f2f002de716 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -3679,7 +3679,7 @@ runs.no_workflows.quick_start = Don't know how to start with Gitea Actions? See runs.no_workflows.documentation = For more information on Gitea Actions, see the documentation. runs.no_runs = The workflow has no runs yet. runs.empty_commit_message = (empty commit message) -runs.expire_log_message = Logs have been purged because they were too old. Site administrator can configure LOG_RETENTION_DAYS to retain logs for a longer duration. +runs.expire_log_message = Logs have been purged because they were too old. workflow.disable = Disable Workflow workflow.disable_success = Workflow '%s' disabled successfully.