You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

cleanup.go 1.2KB

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