diff --git a/ffmpeg/parse/parser.go b/ffmpeg/parse/parser.go index edf0ca03..a3c60a2b 100644 --- a/ffmpeg/parse/parser.go +++ b/ffmpeg/parse/parser.go @@ -33,6 +33,9 @@ type Parser interface { // ReportHistory returns an array of previews logs ReportHistory() []Report + + // TransferReportHistory transfers the report history to another parser + TransferReportHistory(Parser) error } // Config is the config for the Parser implementation @@ -767,3 +770,21 @@ func (p *parser) ReportHistory() []Report { return history } + +func (p *parser) TransferReportHistory(dst Parser) error { + pp, ok := dst.(*parser) + if !ok { + return fmt.Errorf("the target parser is not of the required type") + } + + p.logHistory.Do(func(l interface{}) { + if l == nil { + return + } + + pp.logHistory.Value = l + pp.logHistory = pp.logHistory.Next() + }) + + return nil +} diff --git a/restream/restream.go b/restream/restream.go index fcf38999..597a2e0a 100644 --- a/restream/restream.go +++ b/restream/restream.go @@ -867,6 +867,7 @@ func (r *restream) UpdateProcess(id string, config *app.Config) error { return ErrUnknownProcess } + task.parser.TransferReportHistory(t.parser) t.process.Order = task.process.Order if id != t.id { diff --git a/restream/restream_test.go b/restream/restream_test.go index 11b08240..a0d782b0 100644 --- a/restream/restream_test.go +++ b/restream/restream_test.go @@ -21,10 +21,11 @@ func getDummyRestreamer(portrange net.Portranger, validatorIn, validatorOut ffmp } ffmpeg, err := ffmpeg.New(ffmpeg.Config{ - Binary: binary, - Portrange: portrange, - ValidatorInput: validatorIn, - ValidatorOutput: validatorOut, + Binary: binary, + LogHistoryLength: 3, + Portrange: portrange, + ValidatorInput: validatorIn, + ValidatorOutput: validatorOut, }) if err != nil { return nil, err @@ -437,10 +438,10 @@ func TestLog(t *testing.T) { rs.AddProcess(process) _, err = rs.GetProcessLog("foobar") - require.NotEqual(t, nil, err, "shouldn't be able to get log from non-existing process") + require.Error(t, err) log, err := rs.GetProcessLog(process.ID) - require.Equal(t, nil, err, "should be able to get log from existing process") + require.NoError(t, err) require.Equal(t, 0, len(log.Prelude)) require.Equal(t, 0, len(log.Log)) @@ -461,6 +462,34 @@ func TestLog(t *testing.T) { require.NotEqual(t, 0, len(log.Log)) } +func TestLogTransfer(t *testing.T) { + rs, err := getDummyRestreamer(nil, nil, nil, nil) + require.NoError(t, err) + + process := getDummyProcess() + + err = rs.AddProcess(process) + require.NoError(t, err) + + rs.StartProcess(process.ID) + time.Sleep(3 * time.Second) + rs.StopProcess(process.ID) + + rs.StartProcess(process.ID) + rs.StopProcess(process.ID) + + log, _ := rs.GetProcessLog(process.ID) + + require.Equal(t, 1, len(log.History)) + + err = rs.UpdateProcess(process.ID, process) + require.NoError(t, err) + + log, _ = rs.GetProcessLog(process.ID) + + require.Equal(t, 1, len(log.History)) +} + func TestPlayoutNoRange(t *testing.T) { rs, err := getDummyRestreamer(nil, nil, nil, nil) require.NoError(t, err)