Skip to content

Commit

Permalink
flag assets as deleted
Browse files Browse the repository at this point in the history
  • Loading branch information
gioelecerati committed Apr 3, 2024
1 parent d1a254d commit df4a0d7
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 49 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/golang/glog v1.2.0
github.com/julienschmidt/httprouter v1.3.0
github.com/livepeer/catalyst-api v0.1.2-0.20230925142340-c311569665b4
github.com/livepeer/go-api-client v0.4.19-0.20240308102249-998a7fa05134
github.com/livepeer/go-api-client v0.4.19-0.20240311145302-1abd53df256c
github.com/livepeer/go-tools v0.3.2
github.com/livepeer/livepeer-data v0.7.5-0.20230927031152-b938ac1dc665
github.com/peterbourgon/ff v1.7.1
Expand Down
6 changes: 2 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -281,10 +281,8 @@ github.com/libp2p/go-netroute v0.2.0 h1:0FpsbsvuSnAhXFnCY0VLFbJOzaK0VnP0r1QT/o4n
github.com/libp2p/go-openssl v0.1.0 h1:LBkKEcUv6vtZIQLVTegAil8jbNpJErQ9AnT+bWV+Ooo=
github.com/livepeer/catalyst-api v0.1.2-0.20230925142340-c311569665b4 h1:UfiMdEDGa88yqYD9+i1+ldAex9Kf1+3jbq+wBrmZccM=
github.com/livepeer/catalyst-api v0.1.2-0.20230925142340-c311569665b4/go.mod h1:Ybiub5AGDrDfvyh1MWdIa551LAwhx/6lSpbQlgb1W1Q=
github.com/livepeer/go-api-client v0.4.17 h1:/VKSUTn0hP8dHuAyA2He0kf/f0Av9iOLFnAeNStol6s=
github.com/livepeer/go-api-client v0.4.17/go.mod h1:Jdb+RI7JyzEZOHd1GUuKofwFDKMO/btTa80SdpUpYQw=
github.com/livepeer/go-api-client v0.4.19-0.20240308102249-998a7fa05134 h1:HBMmeVR7QBH7FWJDUFEHwdNf2Krh0qGou3KK+EqA1sY=
github.com/livepeer/go-api-client v0.4.19-0.20240308102249-998a7fa05134/go.mod h1:Jdb+RI7JyzEZOHd1GUuKofwFDKMO/btTa80SdpUpYQw=
github.com/livepeer/go-api-client v0.4.19-0.20240311145302-1abd53df256c h1:KPGkwuKvAbHCADy3hssTCfJVh0wxYMlXVTehEikljCc=
github.com/livepeer/go-api-client v0.4.19-0.20240311145302-1abd53df256c/go.mod h1:Jdb+RI7JyzEZOHd1GUuKofwFDKMO/btTa80SdpUpYQw=
github.com/livepeer/go-tools v0.3.2 h1:5pOUrOmkkGbbcWnpCt2yrSD6cD85G4GcpO4B25NpMJM=
github.com/livepeer/go-tools v0.3.2/go.mod h1:qs31y68b3PQPmSr8nR8l5WQiIWI623z6pqOccqebjos=
github.com/livepeer/livepeer-data v0.7.5-0.20230927031152-b938ac1dc665 h1:EXlI922Fsv9lyIw1LQ7pZN6slCuYya8NQrCFWN8INg4=
Expand Down
105 changes: 61 additions & 44 deletions task/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -581,60 +581,77 @@ func (r *runner) CronJobForAssetDeletion(ctx context.Context) error {
continue

Check warning on line 581 in task/runner.go

View check run for this annotation

Codecov / codecov/patch

task/runner.go#L573-L581

Added lines #L573 - L581 were not covered by tests
}
for _, asset := range assets {
_, _, assetOS, err := r.getAssetAndOS(asset.ID)
err := deleteAsset(asset, r, ctx)
if err != nil {
glog.Errorf("Error getting asset object store session: %v", err)
continue
glog.Errorf("Error deleting asset %v: %v", asset.ID, err)

Check warning on line 586 in task/runner.go

View check run for this annotation

Codecov / codecov/patch

task/runner.go#L583-L586

Added lines #L583 - L586 were not covered by tests
}
}
}
}
}

directory := asset.PlaybackID
var totalDeleted int

// Initially list files
pi, err := assetOS.ListFiles(ctx, directory, "/")
if err != nil {
glog.Errorf("Error listing files for asset %v: %v", asset.ID, err)
continue
}
func deleteAsset(asset *api.Asset, r *runner, ctx context.Context) error {
_, _, assetOS, err := r.getAssetAndOS(asset.ID)
if err != nil {
glog.Errorf("Error getting asset object store session: %v", err)
return err

Check warning on line 597 in task/runner.go

View check run for this annotation

Codecov / codecov/patch

task/runner.go#L593-L597

Added lines #L593 - L597 were not covered by tests
}

for pi != nil {
for _, file := range pi.Files() {
err := assetOS.DeleteFile(ctx, file.Name)
if err != nil {
glog.Errorf("Error deleting file %v: %v", file.Name, err)
continue
}
totalDeleted++
}

if pi.HasNextPage() {
pi, err = pi.NextPage()
if err != nil {
glog.Errorf("Failed to load next page of files for asset %v: %v", asset.ID, err)
break
}
} else {
break // No more pages
}
}
directory := asset.PlaybackID
var totalDeleted int

Check warning on line 601 in task/runner.go

View check run for this annotation

Codecov / codecov/patch

task/runner.go#L600-L601

Added lines #L600 - L601 were not covered by tests

glog.Infof("Deleted %v files from asset=%v", totalDeleted, asset.ID)
// Initially list files
pi, err := assetOS.ListFiles(ctx, directory, "/")
if err != nil {
glog.Errorf("Error listing files for asset %v: %v", asset.ID, err)
return err

Check warning on line 607 in task/runner.go

View check run for this annotation

Codecov / codecov/patch

task/runner.go#L604-L607

Added lines #L604 - L607 were not covered by tests
}

if ipfs := asset.AssetSpec.Storage.IPFS; ipfs != nil {
err = r.UnpinFromIpfs(ctx, ipfs.CID, "cid")
if err != nil {
glog.Errorf("Error unpinning from IPFS %v", ipfs.CID)
}
err = r.UnpinFromIpfs(ctx, ipfs.NFTMetadata.CID, "nftMetadataCid")
if err != nil {
glog.Errorf("Error unpinning metadata from IPFS %v", ipfs.NFTMetadata.CID)
}
for pi != nil {
for _, file := range pi.Files() {
err := assetOS.DeleteFile(ctx, file.Name)
if err != nil {
glog.Errorf("Error deleting file %v: %v", file.Name, err)
continue

Check warning on line 615 in task/runner.go

View check run for this annotation

Codecov / codecov/patch

task/runner.go#L610-L615

Added lines #L610 - L615 were not covered by tests
}
totalDeleted++

Check warning on line 617 in task/runner.go

View check run for this annotation

Codecov / codecov/patch

task/runner.go#L617

Added line #L617 was not covered by tests
}

glog.Infof("Unpinned asset=%v from IPFS", asset.ID)
}
if pi.HasNextPage() {
pi, err = pi.NextPage()
if err != nil {
glog.Errorf("Failed to load next page of files for asset %v: %v", asset.ID, err)
break

Check warning on line 624 in task/runner.go

View check run for this annotation

Codecov / codecov/patch

task/runner.go#L620-L624

Added lines #L620 - L624 were not covered by tests
}
} else {
break // No more pages

Check warning on line 627 in task/runner.go

View check run for this annotation

Codecov / codecov/patch

task/runner.go#L626-L627

Added lines #L626 - L627 were not covered by tests
}
}

glog.Infof("Deleted %v files from asset=%v", totalDeleted, asset.ID)

Check warning on line 631 in task/runner.go

View check run for this annotation

Codecov / codecov/patch

task/runner.go#L631

Added line #L631 was not covered by tests

if ipfs := asset.AssetSpec.Storage.IPFS; ipfs != nil {
err = r.UnpinFromIpfs(ctx, ipfs.CID, "cid")
if err != nil {
glog.Errorf("Error unpinning from IPFS %v", ipfs.CID)
return err

Check warning on line 637 in task/runner.go

View check run for this annotation

Codecov / codecov/patch

task/runner.go#L633-L637

Added lines #L633 - L637 were not covered by tests
}
err = r.UnpinFromIpfs(ctx, ipfs.NFTMetadata.CID, "nftMetadataCid")
if err != nil {
glog.Errorf("Error unpinning metadata from IPFS %v", ipfs.NFTMetadata.CID)
return err

Check warning on line 642 in task/runner.go

View check run for this annotation

Codecov / codecov/patch

task/runner.go#L639-L642

Added lines #L639 - L642 were not covered by tests
}

glog.Infof("Unpinned asset=%v from IPFS", asset.ID)

Check warning on line 645 in task/runner.go

View check run for this annotation

Codecov / codecov/patch

task/runner.go#L645

Added line #L645 was not covered by tests
}

err = r.lapi.FlagAssetAsDeleted(asset.ID)
if err != nil {
glog.Errorf("Error flagging asset as deleted: %v", err)
return err

Check warning on line 651 in task/runner.go

View check run for this annotation

Codecov / codecov/patch

task/runner.go#L648-L651

Added lines #L648 - L651 were not covered by tests
}

return nil

Check warning on line 654 in task/runner.go

View check run for this annotation

Codecov / codecov/patch

task/runner.go#L654

Added line #L654 was not covered by tests
}

type taskErrInfo struct {
Expand Down

0 comments on commit df4a0d7

Please sign in to comment.