From 88a636ba9c863035497be9e07c6e1fcb63c1b130 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Sun, 18 Feb 2024 00:23:25 -0500 Subject: [PATCH] refactor: pass only the upload hash to the cron task --- protocols/s5/tus.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/protocols/s5/tus.go b/protocols/s5/tus.go index b312285..fb06200 100644 --- a/protocols/s5/tus.go +++ b/protocols/s5/tus.go @@ -274,7 +274,7 @@ func (t *TusHandler) ScheduleUpload(ctx context.Context, uploadID string) error task := t.cron.RetryableTask(cron.RetryableTaskParams{ Name: "tusUpload", Function: t.uploadTask, - Args: []interface{}{&upload}, + Args: []interface{}{upload.Hash}, Attempt: 0, Limit: 0, After: func(jobID uuid.UUID, jobName string) { @@ -329,7 +329,14 @@ func (t *TusHandler) SetStorageProtocol(storageProtocol storage.StorageProtocol) t.storageProtocol = storageProtocol } -func (t *TusHandler) uploadTask(ctx context.Context, upload *models.TusUpload) error { +func (t *TusHandler) uploadTask(ctx context.Context, hash []byte) error { + exists, upload := t.UploadExists(ctx, hash) + + if !exists { + t.logger.Error("Upload not found", zap.String("hash", hex.EncodeToString(hash))) + return metadata.ErrNotFound + } + tusUpload, err := t.tusStore.GetUpload(ctx, upload.UploadID) if err != nil { t.logger.Error("Could not get upload", zap.Error(err))