Skip to content

Commit

Permalink
feat(workflow): re-download live thumbnail again after 10 minutes
Browse files Browse the repository at this point in the history
  • Loading branch information
Zibbp committed Feb 18, 2024
1 parent 5a6ada2 commit 3c8a13b
Show file tree
Hide file tree
Showing 3 changed files with 35 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
29 changes: 29 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,32 @@ 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,
},
})

workflow.Sleep(ctx, 10*time.Minute)

Check failure on line 258 in internal/workflows/video.go

View workflow job for this annotation

GitHub Actions / lint

Error return value of `workflow.Sleep` is not checked (errcheck)

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 3c8a13b

Please sign in to comment.