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() []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
}

View File

@@ -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 {

View File

@@ -22,6 +22,7 @@ func getDummyRestreamer(portrange net.Portranger, validatorIn, validatorOut ffmp
ffmpeg, err := ffmpeg.New(ffmpeg.Config{
Binary: binary,
LogHistoryLength: 3,
Portrange: portrange,
ValidatorInput: validatorIn,
ValidatorOutput: validatorOut,
@@ -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)