-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* EgressInfo helpers * add backup_used to egress info * generated protobuf * update helper --------- Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
- Loading branch information
1 parent
3c72d65
commit 391b78f
Showing
4 changed files
with
293 additions
and
198 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package livekit | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"net/http" | ||
"time" | ||
|
||
"github.com/livekit/psrpc" | ||
) | ||
|
||
const ( | ||
MsgLimitReached = "Session limit reached" | ||
MsgStartNotReceived = "Start signal not received" | ||
MsgLimitReachedWithoutStart = "Session limit reached before start signal" | ||
MsgStoppedBeforeStarted = "Stop called before pipeline could start" | ||
|
||
EndReasonAPI = "StopEgress API" | ||
EndReasonKilled = "Process killed" | ||
EndReasonSrcClosed = "Source closed" | ||
EndReasonLimitReached = "Session limit reached" | ||
EndReasonStreamsStopped = "All streams stopped" | ||
EndReasonFailure = "Failure" | ||
) | ||
|
||
func (e *EgressInfo) UpdateStatus(status EgressStatus) { | ||
e.Status = status | ||
e.UpdatedAt = time.Now().UnixNano() | ||
} | ||
|
||
func (e *EgressInfo) SetBackupUsed() { | ||
e.BackupStorageUsed = true | ||
e.UpdatedAt = time.Now().UnixNano() | ||
} | ||
|
||
func (e *EgressInfo) SetEndReason(reason string) { | ||
e.Details = fmt.Sprintf("End reason: %s", reason) | ||
} | ||
|
||
func (e *EgressInfo) SetLimitReached() { | ||
now := time.Now().UnixNano() | ||
e.Status = EgressStatus_EGRESS_LIMIT_REACHED | ||
e.Error = MsgLimitReached | ||
e.ErrorCode = int32(http.StatusRequestEntityTooLarge) | ||
e.UpdatedAt = now | ||
e.EndedAt = now | ||
} | ||
|
||
func (e *EgressInfo) SetAborted(msg string) { | ||
now := time.Now().UnixNano() | ||
e.Status = EgressStatus_EGRESS_ABORTED | ||
e.Error = msg | ||
e.ErrorCode = int32(http.StatusPreconditionFailed) | ||
e.UpdatedAt = now | ||
e.EndedAt = now | ||
} | ||
|
||
func (e *EgressInfo) SetFailed(err error) { | ||
now := time.Now().UnixNano() | ||
e.Status = EgressStatus_EGRESS_FAILED | ||
e.UpdatedAt = now | ||
e.EndedAt = now | ||
e.Error = err.Error() | ||
if e.Details == "" { | ||
e.SetEndReason(EndReasonFailure) | ||
} | ||
|
||
var p psrpc.Error | ||
if errors.As(err, &p) { | ||
// unknown is treated the same as an internal error (500) | ||
if !errors.Is(p.Code(), psrpc.Unknown) { | ||
e.ErrorCode = int32(p.ToHttp()) | ||
} | ||
} | ||
} | ||
|
||
func (e *EgressInfo) SetComplete() { | ||
now := time.Now().UnixNano() | ||
e.Status = EgressStatus_EGRESS_COMPLETE | ||
e.UpdatedAt = now | ||
e.EndedAt = now | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.