refactor: pass only the upload hash to the cron task

This commit is contained in:
Derrick Hammer 2024-02-18 00:23:25 -05:00
parent 15750acec0
commit 88a636ba9c
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 9 additions and 2 deletions

View File

@ -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))