Preserve process log history when updating a process

This commit is contained in:
Ingo Oppermann
2023-04-24 11:59:09 +02:00
parent d807becc8a
commit 6ddd58a124
3 changed files with 57 additions and 6 deletions

View File

@@ -33,6 +33,9 @@ type Parser interface {
// ReportHistory returns an array of previews logs // ReportHistory returns an array of previews logs
ReportHistory() []Report ReportHistory() []Report
// TransferReportHistory transfers the report history to another parser
TransferReportHistory(Parser) error
} }
// Config is the config for the Parser implementation // Config is the config for the Parser implementation
@@ -767,3 +770,21 @@ func (p *parser) ReportHistory() []Report {
return history 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
}

View File

@@ -867,6 +867,7 @@ func (r *restream) UpdateProcess(id string, config *app.Config) error {
return ErrUnknownProcess return ErrUnknownProcess
} }
task.parser.TransferReportHistory(t.parser)
t.process.Order = task.process.Order t.process.Order = task.process.Order
if id != t.id { if id != t.id {

View File

@@ -21,10 +21,11 @@ func getDummyRestreamer(portrange net.Portranger, validatorIn, validatorOut ffmp
} }
ffmpeg, err := ffmpeg.New(ffmpeg.Config{ ffmpeg, err := ffmpeg.New(ffmpeg.Config{
Binary: binary, Binary: binary,
Portrange: portrange, LogHistoryLength: 3,
ValidatorInput: validatorIn, Portrange: portrange,
ValidatorOutput: validatorOut, ValidatorInput: validatorIn,
ValidatorOutput: validatorOut,
}) })
if err != nil { if err != nil {
return nil, err return nil, err
@@ -437,10 +438,10 @@ func TestLog(t *testing.T) {
rs.AddProcess(process) rs.AddProcess(process)
_, err = rs.GetProcessLog("foobar") _, 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) 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.Prelude))
require.Equal(t, 0, len(log.Log)) require.Equal(t, 0, len(log.Log))
@@ -461,6 +462,34 @@ func TestLog(t *testing.T) {
require.NotEqual(t, 0, len(log.Log)) 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) { func TestPlayoutNoRange(t *testing.T) {
rs, err := getDummyRestreamer(nil, nil, nil, nil) rs, err := getDummyRestreamer(nil, nil, nil, nil)
require.NoError(t, err) require.NoError(t, err)