forked from gitea/gitea
1
0
Fork 0

Expire artifacts before deleting them physically (#29241)

https://github.com/go-gitea/gitea/pull/27172#discussion_r1493735466

When cleanup artifacts, it removes storage first. If storage is not
exist (maybe delete manually), it gets error and continue loop. It makes
a dead loop if there are a lot pending but non-existing artifacts.

Now it updates db record at first to avoid keep a lot of pending status
artifacts.
This commit is contained in:
FuXiaoHei 2024-02-18 22:25:14 +08:00 committed by GitHub
parent 4345cac529
commit 68e1d17a5f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 8 additions and 8 deletions

View File

@ -35,14 +35,14 @@ func cleanExpiredArtifacts(taskCtx context.Context) error {
} }
log.Info("Found %d expired artifacts", len(artifacts)) log.Info("Found %d expired artifacts", len(artifacts))
for _, artifact := range artifacts { for _, artifact := range artifacts {
if err := storage.ActionsArtifacts.Delete(artifact.StoragePath); err != nil {
log.Error("Cannot delete artifact %d: %v", artifact.ID, err)
continue
}
if err := actions.SetArtifactExpired(taskCtx, artifact.ID); err != nil { if err := actions.SetArtifactExpired(taskCtx, artifact.ID); err != nil {
log.Error("Cannot set artifact %d expired: %v", artifact.ID, err) log.Error("Cannot set artifact %d expired: %v", artifact.ID, err)
continue continue
} }
if err := storage.ActionsArtifacts.Delete(artifact.StoragePath); err != nil {
log.Error("Cannot delete artifact %d: %v", artifact.ID, err)
continue
}
log.Info("Artifact %d set expired", artifact.ID) log.Info("Artifact %d set expired", artifact.ID)
} }
return nil return nil
@ -59,14 +59,14 @@ func cleanNeedDeleteArtifacts(taskCtx context.Context) error {
} }
log.Info("Found %d artifacts pending deletion", len(artifacts)) log.Info("Found %d artifacts pending deletion", len(artifacts))
for _, artifact := range artifacts { for _, artifact := range artifacts {
if err := storage.ActionsArtifacts.Delete(artifact.StoragePath); err != nil {
log.Error("Cannot delete artifact %d: %v", artifact.ID, err)
continue
}
if err := actions.SetArtifactDeleted(taskCtx, artifact.ID); err != nil { if err := actions.SetArtifactDeleted(taskCtx, artifact.ID); err != nil {
log.Error("Cannot set artifact %d deleted: %v", artifact.ID, err) log.Error("Cannot set artifact %d deleted: %v", artifact.ID, err)
continue continue
} }
if err := storage.ActionsArtifacts.Delete(artifact.StoragePath); err != nil {
log.Error("Cannot delete artifact %d: %v", artifact.ID, err)
continue
}
log.Info("Artifact %d set deleted", artifact.ID) log.Info("Artifact %d set deleted", artifact.ID)
} }
if len(artifacts) < deleteArtifactBatchSize { if len(artifacts) < deleteArtifactBatchSize {