diff --git a/cmd/worker/main.go b/cmd/worker/main.go index 52d43c7e..7c8937cd 100644 --- a/cmd/worker/main.go +++ b/cmd/worker/main.go @@ -170,6 +170,7 @@ func main() { w.RegisterWorkflow(workflows.ArchiveTwitchLiveVideoWorkflow) w.RegisterWorkflow(workflows.DownloadTwitchLiveChatWorkflow) w.RegisterWorkflow(workflows.DownloadTwitchLiveThumbnailsWorkflow) + w.RegisterWorkflow(workflows.DownloadTwitchLiveThumbnailsWorkflowWait) w.RegisterWorkflow(workflows.DownloadTwitchLiveVideoWorkflow) w.RegisterWorkflow(workflows.SaveTwitchLiveVideoInfoWorkflow) w.RegisterWorkflow(workflows.ArchiveTwitchLiveChatWorkflow) diff --git a/internal/activities/video.go b/internal/activities/video.go index 223498be..33d5298f 100644 --- a/internal/activities/video.go +++ b/internal/activities/video.go @@ -231,11 +231,6 @@ func DownloadTwitchThumbnails(ctx context.Context, input dto.ArchiveVideoInput) func DownloadTwitchLiveThumbnails(ctx context.Context, input dto.ArchiveVideoInput) error { - _, dbErr := database.DB().Client.Queue.UpdateOneID(input.Queue.ID).SetTaskVodDownloadThumbnail(utils.Running).Save(ctx) - if dbErr != nil { - return dbErr - } - twitchService := twitch.NewService() stream, err := twitchService.GetStreams(fmt.Sprintf("?user_login=%s", input.Channel.Name)) if err != nil { @@ -246,6 +241,11 @@ func DownloadTwitchLiveThumbnails(ctx context.Context, input dto.ArchiveVideoInp return temporal.NewApplicationError(err.Error(), "", nil) } + _, dbErr := database.DB().Client.Queue.UpdateOneID(input.Queue.ID).SetTaskVodDownloadThumbnail(utils.Running).Save(ctx) + if dbErr != nil { + return dbErr + } + if len(stream.Data) == 0 { _, dbErr := database.DB().Client.Queue.UpdateOneID(input.Queue.ID).SetTaskVodDownloadThumbnail(utils.Failed).Save(ctx) if dbErr != nil { diff --git a/internal/workflows/video.go b/internal/workflows/video.go index c8ca0a52..d4904c91 100644 --- a/internal/workflows/video.go +++ b/internal/workflows/video.go @@ -127,6 +127,9 @@ func ArchiveLiveVideoWorkflow(ctx workflow.Context, input dto.ArchiveVideoInput) return err } + // download thumbnails againt in 5 minutes + _ = workflow.ExecuteChildWorkflow(ctx, DownloadTwitchLiveThumbnailsWorkflowWait, input) + // save video info err = workflow.ExecuteChildWorkflow(ctx, SaveTwitchLiveVideoInfoWorkflow, input).Get(ctx, nil) if err != nil { @@ -241,6 +244,35 @@ func DownloadTwitchLiveThumbnailsWorkflow(ctx workflow.Context, input dto.Archiv return nil } +func DownloadTwitchLiveThumbnailsWorkflowWait(ctx workflow.Context, input dto.ArchiveVideoInput) error { + ctx = workflow.WithActivityOptions(ctx, workflow.ActivityOptions{ + StartToCloseTimeout: 15 * time.Minute, + RetryPolicy: &temporal.RetryPolicy{ + InitialInterval: 1 * time.Minute, + BackoffCoefficient: 2, + MaximumAttempts: 2, + MaximumInterval: 15 * time.Minute, + }, + }) + + err := workflow.Sleep(ctx, 10*time.Minute) + if err != nil { + return err + } + + err = workflow.ExecuteActivity(ctx, activities.DownloadTwitchLiveThumbnails, input).Get(ctx, nil) + if err != nil { + return workflowErrorHandler(err, input, "download-thumbnails") + } + + err = checkIfTasksAreDone(input) + if err != nil { + return err + } + + return nil +} + // *Low Level Workflow* func SaveTwitchVideoInfoWorkflow(ctx workflow.Context, input dto.ArchiveVideoInput) error { ctx = workflow.WithActivityOptions(ctx, workflow.ActivityOptions{