feat: update job
This commit is contained in:
@@ -70,20 +70,24 @@ func (w *VideoStoreShortWorker) Work(ctx context.Context, job *Job[VideoStoreSho
|
||||
}
|
||||
|
||||
// get file md5
|
||||
log.Infof("pending get file md5 %s", job.Args.FilePath)
|
||||
fileMd5, err := utils.GetFileMd5(job.Args.FilePath)
|
||||
if err != nil {
|
||||
log.Errorf("Error getting file md5: %v", err)
|
||||
return JobCancel(err)
|
||||
}
|
||||
log.Infof("got file md5 %s %s", job.Args.FilePath, fileMd5)
|
||||
|
||||
filePath := w.oss.GetSavePath(fileMd5 + filepath.Ext(job.Args.FilePath))
|
||||
|
||||
// get file size
|
||||
log.Infof("pending get file size %s", job.Args.FilePath)
|
||||
fileSize, err := utils.GetFileSize(job.Args.FilePath)
|
||||
if err != nil {
|
||||
log.Errorf("Error getting file size: %v", err)
|
||||
return JobCancel(err)
|
||||
}
|
||||
log.Infof("got file size %s %d", job.Args.FilePath, fileSize)
|
||||
|
||||
// save to db and relate to master
|
||||
mediaModel := &model.Medias{
|
||||
@@ -101,18 +105,20 @@ func (w *VideoStoreShortWorker) Work(ctx context.Context, job *Job[VideoStoreSho
|
||||
}
|
||||
|
||||
// upload to oss
|
||||
log.Infof("pending upload file to oss %s", job.Args.FilePath)
|
||||
if err := w.oss.Upload(ctx, job.Args.FilePath, filePath, ali.WithInternal()); err != nil {
|
||||
log.Errorf("Error uploading file to OSS: %v", err)
|
||||
return err
|
||||
}
|
||||
|
||||
log.Infof("pending create media record %s", job.Args.FilePath)
|
||||
if err := models.Medias.Create(ctx, mediaModel); err != nil {
|
||||
log.Errorf("Error saving media record: %v data: %+v", err, mediaModel)
|
||||
return err
|
||||
}
|
||||
|
||||
log.Infof("Media record created with path: %s and hash: %s", filePath, fileMd5)
|
||||
|
||||
log.Infof("pending remove local storage file %s", job.Args.FilePath)
|
||||
if w.job.Add(&RemoveFile{FilePath: job.Args.FilePath}); err != nil {
|
||||
log.Errorf("Error removing original file: %v", err)
|
||||
}
|
||||
|
||||
@@ -77,7 +77,10 @@ func (c *OSSClient) Download(ctx context.Context, path, dest string, opts ...OSS
|
||||
client = c.internalClient
|
||||
}
|
||||
|
||||
if _, err := client.GetObjectToFile(ctx, request, dest); err != nil {
|
||||
ossFuncs := []func(*oss.Options){
|
||||
oss.OpReadWriteTimeout(time.Minute * 20),
|
||||
}
|
||||
if _, err := client.GetObjectToFile(ctx, request, dest, ossFuncs...); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user