code.gitea.io/gitea@v1.21.7/services/actions/cleanup.go (about) 1 // Copyright 2023 The Gitea Authors. All rights reserved. 2 // SPDX-License-Identifier: MIT 3 4 package actions 5 6 import ( 7 "context" 8 "time" 9 10 "code.gitea.io/gitea/models/actions" 11 "code.gitea.io/gitea/modules/log" 12 "code.gitea.io/gitea/modules/storage" 13 ) 14 15 // Cleanup removes expired actions logs, data and artifacts 16 func Cleanup(taskCtx context.Context, olderThan time.Duration) error { 17 // TODO: clean up expired actions logs 18 19 // clean up expired artifacts 20 return CleanupArtifacts(taskCtx) 21 } 22 23 // CleanupArtifacts removes expired artifacts and set records expired status 24 func CleanupArtifacts(taskCtx context.Context) error { 25 artifacts, err := actions.ListNeedExpiredArtifacts(taskCtx) 26 if err != nil { 27 return err 28 } 29 log.Info("Found %d expired artifacts", len(artifacts)) 30 for _, artifact := range artifacts { 31 if err := storage.ActionsArtifacts.Delete(artifact.StoragePath); err != nil { 32 log.Error("Cannot delete artifact %d: %v", artifact.ID, err) 33 continue 34 } 35 if err := actions.SetArtifactExpired(taskCtx, artifact.ID); err != nil { 36 log.Error("Cannot set artifact %d expired: %v", artifact.ID, err) 37 continue 38 } 39 log.Info("Artifact %d set expired", artifact.ID) 40 } 41 return nil 42 }