Skip to content

Commit

Permalink
Merge pull request #372 from Zibbp/fixes-download-live-thumbnail-again
Browse files Browse the repository at this point in the history
feat(workflow): re-download live thumbnail again after 10 minutes
  • Loading branch information
Zibbp committed Feb 18, 2024
2 parents 5a6ada2 + f9c58db commit 5280da4
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 5 deletions.
1 change: 1 addition & 0 deletions cmd/worker/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions internal/activities/video.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
32 changes: 32 additions & 0 deletions internal/workflows/video.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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{
Expand Down

0 comments on commit 5280da4

Please sign in to comment.