✨ File operations queue
This commit is contained in:
@ -13,6 +13,7 @@ import (
|
||||
"git.solsynth.dev/hydrogen/paperclip/pkg/internal/database"
|
||||
"git.solsynth.dev/hydrogen/paperclip/pkg/internal/models"
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/spf13/viper"
|
||||
|
||||
_ "image/gif"
|
||||
@ -26,6 +27,15 @@ func PublishAnalyzeTask(file models.Attachment) {
|
||||
fileAnalyzeQueue <- file
|
||||
}
|
||||
|
||||
func StartConsumeAnalyzeTask() {
|
||||
for {
|
||||
task := <-fileAnalyzeQueue
|
||||
if err := AnalyzeAttachment(task); err != nil {
|
||||
log.Error().Err(err).Any("task", task).Msg("A file analyze task failed...")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func AnalyzeAttachment(file models.Attachment) error {
|
||||
if file.Destination != models.AttachmentDstTemporary {
|
||||
return fmt.Errorf("attachment isn't in temporary storage, unable to analyze")
|
||||
|
@ -154,7 +154,7 @@ func DeleteAttachment(item models.Attachment) error {
|
||||
tx.Commit()
|
||||
|
||||
if dat.RefCount == 0 {
|
||||
return DeleteFile(dat)
|
||||
PublishDeleteFileTask(dat)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -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 {
|
||||
|
Reference in New Issue
Block a user