mirror of
https://github.com/datarhei/core.git
synced 2025-10-06 00:17:07 +08:00
Fix receiving proper current command args, simplifying retrieval of last log line
This commit is contained in:
@@ -32,6 +32,9 @@ type Parser interface {
|
||||
|
||||
// ReportHistory returns an array of previews logs
|
||||
ReportHistory() []ReportHistoryEntry
|
||||
|
||||
// LastLogline returns the last parsed log line
|
||||
LastLogline() string
|
||||
}
|
||||
|
||||
// Config is the config for the Parser implementation
|
||||
@@ -71,6 +74,8 @@ type parser struct {
|
||||
logHistory *ring.Ring
|
||||
logHistoryLength int
|
||||
|
||||
lastLogline string
|
||||
|
||||
progress struct {
|
||||
ffmpeg ffmpegProgress
|
||||
avstream map[string]ffmpegAVstream
|
||||
@@ -622,6 +627,8 @@ func (p *parser) addLog(line string) {
|
||||
p.lock.log.Lock()
|
||||
defer p.lock.log.Unlock()
|
||||
|
||||
p.lastLogline = line
|
||||
|
||||
p.log.Value = process.Line{
|
||||
Timestamp: time.Now(),
|
||||
Data: line,
|
||||
@@ -646,6 +653,13 @@ func (p *parser) Log() []process.Line {
|
||||
return log
|
||||
}
|
||||
|
||||
func (p *parser) LastLogline() string {
|
||||
p.lock.log.RLock()
|
||||
defer p.lock.log.RUnlock()
|
||||
|
||||
return p.lastLogline
|
||||
}
|
||||
|
||||
func (p *parser) ResetStats() {
|
||||
p.lock.progress.Lock()
|
||||
defer p.lock.progress.Unlock()
|
||||
|
@@ -64,26 +64,14 @@ type Config struct {
|
||||
|
||||
// Status represents the current status of a process
|
||||
type Status struct {
|
||||
// State is the current state of the process. See stateType for the known states.
|
||||
State string
|
||||
|
||||
// States is the cumulative history of states the process had.
|
||||
States States
|
||||
|
||||
// Order is the wanted condition of process, either "start" or "stop"
|
||||
Order string
|
||||
|
||||
// Duration is the time since the last change of the state
|
||||
Duration time.Duration
|
||||
|
||||
// Time is the time of the last change of the state
|
||||
Time time.Time
|
||||
|
||||
// Used CPU in percent
|
||||
CPU float64
|
||||
|
||||
// Used memory in bytes
|
||||
Memory uint64
|
||||
State string // State is the current state of the process. See stateType for the known states.
|
||||
States States // States is the cumulative history of states the process had.
|
||||
Order string // Order is the wanted condition of process, either "start" or "stop"
|
||||
Duration time.Duration // Duration is the time since the last change of the state
|
||||
Time time.Time // Time is the time of the last change of the state
|
||||
CPU float64 // Used CPU in percent
|
||||
Memory uint64 // Used memory in bytes
|
||||
CommandArgs []string // Currently running command arguments
|
||||
}
|
||||
|
||||
// States
|
||||
@@ -205,12 +193,14 @@ var _ Process = &process{}
|
||||
func New(config Config) (Process, error) {
|
||||
p := &process{
|
||||
binary: config.Binary,
|
||||
args: config.Args,
|
||||
cmd: nil,
|
||||
parser: config.Parser,
|
||||
logger: config.Logger,
|
||||
}
|
||||
|
||||
p.args = make([]string, len(config.Args))
|
||||
copy(p.args, config.Args)
|
||||
|
||||
// This is a loose check on purpose. If the e.g. the binary
|
||||
// doesn't exist or it is not executable, it will be
|
||||
// reflected in the resulting state.
|
||||
@@ -414,6 +404,9 @@ func (p *process) Status() Status {
|
||||
Memory: memory,
|
||||
}
|
||||
|
||||
s.CommandArgs = make([]string, len(p.args))
|
||||
copy(s.CommandArgs, p.args)
|
||||
|
||||
return s
|
||||
}
|
||||
|
||||
|
@@ -1264,8 +1264,8 @@ func (r *restream) GetProcessState(id string) (*app.State, error) {
|
||||
state.CPU = status.CPU
|
||||
state.Duration = status.Duration.Round(10 * time.Millisecond).Seconds()
|
||||
state.Reconnect = -1
|
||||
state.Command = make([]string, len(task.command))
|
||||
copy(state.Command, task.command)
|
||||
state.Command = status.CommandArgs
|
||||
state.LastLog = task.parser.LastLogline()
|
||||
|
||||
if state.Order == "start" && !task.ffmpeg.IsRunning() && task.config.Reconnect {
|
||||
state.Reconnect = float64(task.config.ReconnectDelay) - state.Duration
|
||||
@@ -1293,12 +1293,6 @@ func (r *restream) GetProcessState(id string) (*app.State, error) {
|
||||
state.Progress.Output[i].ID = task.process.Config.Output[p.Index].ID
|
||||
}
|
||||
|
||||
report := task.parser.Report()
|
||||
|
||||
if len(report.Log) != 0 {
|
||||
state.LastLog = report.Log[len(report.Log)-1].Data
|
||||
}
|
||||
|
||||
return state, nil
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user