Clear up old Actions logs (#31735)
Part of #24256. Clear up old action logs to free up storage space. Users will see a message indicating that the log has been cleared if they view old tasks. <img width="1361" alt="image" src="https://github.com/user-attachments/assets/9f0f3a3a-bc5a-402f-90ca-49282d196c22"> Docs: https://gitea.com/gitea/docs/pulls/40 --------- Co-authored-by: silverwind <me@silverwind.io> (cherry picked from commit 687c1182482ad9443a5911c068b317a91c91d586) Conflicts: custom/conf/app.example.ini routers/web/repo/actions/view.go trivial context conflict
This commit is contained in:
parent
5734499778
commit
0c40cff9a4
9 changed files with 129 additions and 18 deletions
|
@ -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,16 @@ func StopTask(ctx context.Context, taskID int64, status Status) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
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 = ?", olderThan, false).
|
||||
Limit(limit).
|
||||
Find(&tasks)
|
||||
}
|
||||
|
||||
func isSubset(set, subset []string) bool {
|
||||
m := make(container.Set[string], len(set))
|
||||
for _, v := range set {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue