mirror of
https://github.com/langhuihui/monibuca.git
synced 2025-09-27 01:15:52 +08:00
35 lines
678 B
Go
35 lines
678 B
Go
package pkg
|
|
|
|
import (
|
|
"context"
|
|
"log/slog"
|
|
"time"
|
|
)
|
|
|
|
const TraceLevel = slog.Level(-8)
|
|
|
|
type Unit struct {
|
|
ID int
|
|
StartTime time.Time
|
|
*slog.Logger `json:"-" yaml:"-"`
|
|
context.Context `json:"-" yaml:"-"`
|
|
context.CancelCauseFunc `json:"-" yaml:"-"`
|
|
}
|
|
|
|
func (unit *Unit) Trace(msg string, fields ...any) {
|
|
unit.Log(unit.Context, TraceLevel, msg, fields...)
|
|
}
|
|
|
|
func (unit *Unit) IsStopped() bool {
|
|
return unit.StopReason() != nil
|
|
}
|
|
|
|
func (unit *Unit) StopReason() error {
|
|
return context.Cause(unit.Context)
|
|
}
|
|
|
|
func (unit *Unit) Stop(err error) {
|
|
unit.Info("stop", "reason", err.Error())
|
|
unit.CancelCauseFunc(err)
|
|
}
|