-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Send overall (rather than per-stage) completion ratio to Studio #33
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,9 +46,13 @@ func (c CallbackClient) DoWithRetries(r *http.Request) error { | |
return nil | ||
} | ||
|
||
func (c CallbackClient) SendTranscodeStatus(url string, status TranscodeStatus, completionRatio float32) error { | ||
// Sends a Transcode Status message to the Client (initially just Studio) | ||
// The status strings will be useful for debugging where in the workflow we got to, but everything | ||
// in Studio will be driven off the overall "Completion Ratio". | ||
// This method will accept the completion ratio of the current stage and will translate that into the overall ratio | ||
func (c CallbackClient) SendTranscodeStatus(url string, status TranscodeStatus, currentStageCompletionRatio float64) error { | ||
tsm := TranscodeStatusMessage{ | ||
CompletionRatio: completionRatio, | ||
CompletionRatio: overallCompletionRatio(status, currentStageCompletionRatio), | ||
Status: status.String(), | ||
Timestamp: config.Clock.GetTimestampUTC(), | ||
} | ||
|
@@ -86,21 +90,54 @@ func (c CallbackClient) SendTranscodeStatusError(callbackURL, errorMsg string) e | |
return c.DoWithRetries(r) | ||
} | ||
|
||
// Calculate the overall completion ratio based on the completion ratio of the current stage. | ||
// The weighting will need to be tweaked as we understand better the relative time spent in the | ||
// segmenting vs. transcoding stages. | ||
func overallCompletionRatio(status TranscodeStatus, currentStageCompletionRatio float64) float64 { | ||
// Sanity check the inputs are within the 0-1 bounds | ||
if currentStageCompletionRatio < 0 { | ||
currentStageCompletionRatio = 0 | ||
} | ||
if currentStageCompletionRatio > 1 { | ||
currentStageCompletionRatio = 1 | ||
} | ||
|
||
// Define the "base" numbers - e.g the overall ratio we start each stage at | ||
var TranscodeStatusPreparingBase float64 = 0.0 | ||
var TranscodeStatusPreparingTranscodingBase float64 = 0.4 | ||
var TranscodeStatusCompletedBase float64 = 1 | ||
|
||
switch status { | ||
case TranscodeStatusPreparing: | ||
return TranscodeStatusPreparingBase + (currentStageCompletionRatio * (TranscodeStatusPreparingTranscodingBase - TranscodeStatusPreparingBase)) | ||
case TranscodeStatusPreparingCompleted: | ||
return TranscodeStatusPreparingTranscodingBase | ||
case TranscodeStatusTranscoding: | ||
return TranscodeStatusPreparingTranscodingBase + (currentStageCompletionRatio * (TranscodeStatusCompletedBase - TranscodeStatusPreparingTranscodingBase)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Another way of implementing this, to have the more complex math only in 1 place, would be to have 2 vars "start" and "end" and force the switch status {
case TranscodeStatusPreparing, TranscodeStatusPreparingCompleted:
start, end = 0, 0.4
case TranscodeStatusTranscoding, TranscodeStatusTranscodingCompleted:
start, end = 0.4, 1
}
if (status == TranscodeStatusPreparingCompleted || status == TranscodeStatusTranscodingCompleted) {
currentStageCompletionRatio = 1
} Then there could be a single progress-scaling function like this: https://github.com/livepeer/task-runner/blob/4d1ae1768c01e979969bf7f00b81267db05e299c/task/progress.go#L66 Certainly not a required change, just tripping on the impl. Could make sense when we start adding more steps here. WDYT? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like that a lot! |
||
case TranscodeStatusCompleted: | ||
return TranscodeStatusCompletedBase | ||
default: | ||
// Either unhandled or an error | ||
return -1 | ||
} | ||
} | ||
|
||
// An enum of potential statuses a Transcode job can have | ||
|
||
type TranscodeStatus int | ||
|
||
const ( | ||
TranscodeStatusPreparing TranscodeStatus = iota | ||
TranscodeStatusPreparingCompleted | ||
TranscodeStatusTranscoding | ||
TranscodeStatusCompleted | ||
TranscodeStatusError | ||
) | ||
|
||
type TranscodeStatusMessage struct { | ||
CompletionRatio float32 `json:"completion_ratio,omitempty"` | ||
CompletionRatio float64 `json:"completion_ratio"` // No omitempty or we lose this for 0% completion case | ||
Error string `json:"error,omitempty"` | ||
Retriable bool `json:"retriable,omitempty"` | ||
Retriable *bool `json:"retriable,omitempty"` // Has to be a pointer or we can't differentiate omission from 'false' | ||
Status string `json:"status,omitempty"` | ||
Timestamp int64 `json:"timestamp"` | ||
} | ||
|
@@ -109,10 +146,12 @@ func (ts TranscodeStatus) String() string { | |
switch ts { | ||
case TranscodeStatusPreparing: | ||
return "preparing" | ||
case TranscodeStatusPreparingCompleted: | ||
return "preparing-completed" | ||
case TranscodeStatusTranscoding: | ||
return "transcoding" | ||
case TranscodeStatusCompleted: | ||
return "completed" | ||
return "transcoding-completed" | ||
case TranscodeStatusError: | ||
return "error" | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should it be only "Transcoding"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The "Base" was trying to signify that this is the lower limit / floor / whatever, open to suggestions for better names though. Maybe "Floor"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just realised what you were actually pointing out 👓