From 418d0fc102c304853762a769015a0b801990be29 Mon Sep 17 00:00:00 2001 From: Dmitry Sergeev Date: Thu, 27 Aug 2026 09:38:35 +0300 Subject: [PATCH] define playback worker status --- internal/playback/state.go | 21 +++++++++++++++++++++ internal/playback/state_test.go | 27 +++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 internal/playback/state_test.go diff --git a/internal/playback/state.go b/internal/playback/state.go index af6f185..4fea8aa 100644 --- a/internal/playback/state.go +++ b/internal/playback/state.go @@ -1,5 +1,15 @@ package playback +import "time" + +type Unit uint8 + +const ( + UnitVideo Unit = iota + UnitAudio + UnitSync +) + type State uint8 const ( @@ -10,3 +20,14 @@ const ( StateFailed StateStopping ) + +type Status struct { + Unit Unit + State State + Attempt int + FailedAttempts int + RetryIn time.Duration + Err error +} + +type StatusObserver func(Status) diff --git a/internal/playback/state_test.go b/internal/playback/state_test.go new file mode 100644 index 0000000..b3d20e6 --- /dev/null +++ b/internal/playback/state_test.go @@ -0,0 +1,27 @@ +package playback + +import ( + "errors" + "testing" + "time" +) + +func TestStatusPreservesValues(t *testing.T) { + wantErr := errors.New("producer missing") + status := Status{ + Unit: UnitVideo, + State: StateReconnecting, + Attempt: 2, + FailedAttempts: 1, + RetryIn: time.Second, + Err: wantErr, + } + + if status.Unit != UnitVideo { + t.Errorf("Unit = %v, want %v", status.Unit, UnitVideo) + } + // Check the remaining fields similarly. + if !errors.Is(status.Err, wantErr) { + t.Errorf("Err = %v, want %v", status.Err, wantErr) + } +}