Skip to content

Commit 68e1d17

Browse files
authored
Expire artifacts before deleting them physically (#29241)
#27172 (comment) 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.
1 parent 4345cac commit 68e1d17

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

Diff for: services/actions/cleanup.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,14 @@ func cleanExpiredArtifacts(taskCtx context.Context) error {
3535
}
3636
log.Info("Found %d expired artifacts", len(artifacts))
3737
for _, artifact := range artifacts {
38-
if err := storage.ActionsArtifacts.Delete(artifact.StoragePath); err != nil {
39-
log.Error("Cannot delete artifact %d: %v", artifact.ID, err)
40-
continue
41-
}
4238
if err := actions.SetArtifactExpired(taskCtx, artifact.ID); err != nil {
4339
log.Error("Cannot set artifact %d expired: %v", artifact.ID, err)
4440
continue
4541
}
42+
if err := storage.ActionsArtifacts.Delete(artifact.StoragePath); err != nil {
43+
log.Error("Cannot delete artifact %d: %v", artifact.ID, err)
44+
continue
45+
}
4646
log.Info("Artifact %d set expired", artifact.ID)
4747
}
4848
return nil
@@ -59,14 +59,14 @@ func cleanNeedDeleteArtifacts(taskCtx context.Context) error {
5959
}
6060
log.Info("Found %d artifacts pending deletion", len(artifacts))
6161
for _, artifact := range artifacts {
62-
if err := storage.ActionsArtifacts.Delete(artifact.StoragePath); err != nil {
63-
log.Error("Cannot delete artifact %d: %v", artifact.ID, err)
64-
continue
65-
}
6662
if err := actions.SetArtifactDeleted(taskCtx, artifact.ID); err != nil {
6763
log.Error("Cannot set artifact %d deleted: %v", artifact.ID, err)
6864
continue
6965
}
66+
if err := storage.ActionsArtifacts.Delete(artifact.StoragePath); err != nil {
67+
log.Error("Cannot delete artifact %d: %v", artifact.ID, err)
68+
continue
69+
}
7070
log.Info("Artifact %d set deleted", artifact.ID)
7171
}
7272
if len(artifacts) < deleteArtifactBatchSize {

0 commit comments

Comments
 (0)