Skip to content

Commit

Permalink
feat: retain file after 3 days
Browse files Browse the repository at this point in the history
  • Loading branch information
KagChi committed Oct 17, 2023
1 parent 5ea5645 commit 56dc194
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ S3_SECRET=
S3_USE_SSL=
S3_BUCKET=

CRON_JOB=0 */2 * * *
CRON_JOB=0 */2 * * *
FILE_PATH=Database
11 changes: 10 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func main() {
currentTime := time.Now()
year, month, day := currentTime.Date()
date := fmt.Sprintf("%d-%02d-%02d", year, month, day)
fileName := fmt.Sprintf("Database/%d/%d/%d/%s (%s).zip", year, month, day, date, randHex)
fileName := fmt.Sprintf("%s/%d/%d/%d/%s (%s).zip", os.Getenv("FILE_PATH"), year, month, day, date, randHex)

log.Printf("File name: %s", fileName)

Expand All @@ -112,6 +112,15 @@ func main() {
}

log.Printf("Uploaded the file to S3")

retainTime := currentTime.Add(3 * 24 * time.Hour)

client.PutObjectRetention(context.Background(), os.Getenv("S3_BUCKET"), fileName, minio.PutObjectRetentionOptions{
RetainUntilDate: &retainTime,
VersionID: fmt.Sprintf("Retain %s after 3 days", fileName),
})

log.Printf("%s will be retained after 3 days", fileName)
},
)

Expand Down

0 comments on commit 56dc194

Please sign in to comment.