diff options
author | FuXiaoHei <fuxiaohei@vip.qq.com> | 2024-02-18 18:33:50 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-18 10:33:50 +0000 |
commit | 67adc5c1dc3470dab96053c2e77351f3a3f8062b (patch) | |
tree | 51e10d6b875d2d8aee0211f4a68a3ae52996a059 /services/actions | |
parent | 7430eb9e7f04a2923cee1f144947cf5fcce39ef8 (diff) | |
download | gitea-67adc5c1dc3470dab96053c2e77351f3a3f8062b.tar.gz gitea-67adc5c1dc3470dab96053c2e77351f3a3f8062b.zip |
Artifact deletion in actions ui (#27172)
Add deletion link in runs view page.
Fix #26315
![image](https://github.com/go-gitea/gitea/assets/2142787/aa65a4ab-f434-4deb-b953-21e63c212033)
When click deletion button. It marks this artifact `need-delete`.
This artifact would be deleted when actions cleanup cron task.
Diffstat (limited to 'services/actions')
-rw-r--r-- | services/actions/cleanup.go | 38 |
1 files changed, 37 insertions, 1 deletions
diff --git a/services/actions/cleanup.go b/services/actions/cleanup.go index 785eeb5838..59e2cc85de 100644 --- a/services/actions/cleanup.go +++ b/services/actions/cleanup.go @@ -20,8 +20,15 @@ func Cleanup(taskCtx context.Context, olderThan time.Duration) error { return CleanupArtifacts(taskCtx) } -// CleanupArtifacts removes expired artifacts and set records expired status +// CleanupArtifacts removes expired add need-deleted artifacts and set records expired status func CleanupArtifacts(taskCtx context.Context) error { + if err := cleanExpiredArtifacts(taskCtx); err != nil { + return err + } + return cleanNeedDeleteArtifacts(taskCtx) +} + +func cleanExpiredArtifacts(taskCtx context.Context) error { artifacts, err := actions.ListNeedExpiredArtifacts(taskCtx) if err != nil { return err @@ -40,3 +47,32 @@ func CleanupArtifacts(taskCtx context.Context) error { } return nil } + +// deleteArtifactBatchSize is the batch size of deleting artifacts +const deleteArtifactBatchSize = 100 + +func cleanNeedDeleteArtifacts(taskCtx context.Context) error { + for { + artifacts, err := actions.ListPendingDeleteArtifacts(taskCtx, deleteArtifactBatchSize) + if err != nil { + return err + } + log.Info("Found %d artifacts pending deletion", len(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 { + log.Error("Cannot set artifact %d deleted: %v", artifact.ID, err) + continue + } + log.Info("Artifact %d set deleted", artifact.ID) + } + if len(artifacts) < deleteArtifactBatchSize { + log.Debug("No more artifacts pending deletion") + break + } + } + return nil +} |