mirror of
https://github.com/datarhei/core.git
synced 2025-09-27 12:22:28 +08:00
Preserve process log history when updating a process
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
@@ -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 {
|
||||
|
@@ -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)
|
||||
|
Reference in New Issue
Block a user