File operations queue

This commit is contained in:
2024-07-29 00:53:40 +08:00
parent 089a9ecd9d
commit 82cb45ec53
5 changed files with 39 additions and 1 deletions

View File

@@ -10,9 +10,25 @@ import (
jsoniter "github.com/json-iterator/go"
"github.com/minio/minio-go/v7"
"github.com/minio/minio-go/v7/pkg/credentials"
"github.com/rs/zerolog/log"
"github.com/spf13/viper"
)
var fileDeletionQueue = make(chan models.Attachment, 256)
func PublishDeleteFileTask(file models.Attachment) {
fileDeletionQueue <- file
}
func StartConsumeDeletionTask() {
for {
task := <-fileDeletionQueue
if err := DeleteFile(task); err != nil {
log.Error().Err(err).Any("task", task).Msg("A file deletion task failed...")
}
}
}
func DeleteFile(meta models.Attachment) error {
var destMap map[string]any
if meta.Destination == models.AttachmentDstTemporary {