Created
August 22, 2023 13:22
-
-
Save rossjones/7f6c161f074be87655ec0e6e3dc2850c to your computer and use it in GitHub Desktop.
Deletes old bacalhau job output
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Finds all of the job output that is older than 1month | |
# old and unpins it from IPFS so that the GC can clean | |
# it up. | |
# | |
# Requires JQ (https://jqlang.github.io/jq/download/) | |
# Get the unix timestamp (since the epoch) for the date 1 month ago. | |
LAST_MONTH=$(date -v"-1m" +%s) | |
# List all of the jobs with the newest first, and retrieve up to 1000 jobs | |
LIST_OUTPUT=`bacalhau list --sort-by created_at --number=1000 --all --output json` | |
# Get all of the jobs that are Completed, and then those where the executions have | |
# one whose state is completed. | |
# For the retrieved Executions, create a new JSON doc with the execution create time | |
# and the CID of the results | |
# Filter this final JSON document to only those CIDs created before our LAST_MONTH cutoff. | |
echo $LIST_OUTPUT \ | |
| jq '.[] | select(.State.State=="Completed") | .State.Executions | .[] | select(.State=="Completed")' \ | |
| jq '{date:.CreateTime,cid:.PublishedResults.CID}' \ | |
| jq -s \ | |
| jq --arg LASTMONTH "${LAST_MONTH}" '.[] | select ( .date | .[0:19] +"Z" | fromdateiso8601 < ($LASTMONTH|tonumber)) | .cid ' \ | |
| tee /dev/tty \ | |
| xargs ipfs pin rm |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment