diff --git a/docs/docs.go b/docs/docs.go index d739b911..cc0db1a3 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -1608,12 +1608,6 @@ const docTemplate = `{ "summary": "List of processes in the cluster", "operationId": "cluster-3-get-all-processes", "parameters": [ - { - "type": "string", - "description": "Domain to act on", - "name": "domain", - "in": "query" - }, { "type": "string", "description": "Comma separated list of fields (config, state, report, metadata) that will be part of the output. If empty, all fields will be part of the output.", @@ -3456,12 +3450,6 @@ const docTemplate = `{ "summary": "List all known processes", "operationId": "process-3-get-all", "parameters": [ - { - "type": "string", - "description": "Domain to act on", - "name": "domain", - "in": "query" - }, { "type": "string", "description": "Comma separated list of fields (config, state, report, metadata) that will be part of the output. If empty, all fields will be part of the output.", @@ -7483,6 +7471,9 @@ const docTemplate = `{ "type": "integer", "format": "int64" }, + "domain": { + "type": "string" + }, "exit_state": { "type": "string" }, @@ -7528,6 +7519,10 @@ const docTemplate = `{ "order": { "type": "string" }, + "pid": { + "type": "integer", + "format": "int32" + }, "progress": { "$ref": "#/definitions/api.Progress" }, diff --git a/docs/swagger.json b/docs/swagger.json index ed0e77ba..b3f4b5f9 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -1601,12 +1601,6 @@ "summary": "List of processes in the cluster", "operationId": "cluster-3-get-all-processes", "parameters": [ - { - "type": "string", - "description": "Domain to act on", - "name": "domain", - "in": "query" - }, { "type": "string", "description": "Comma separated list of fields (config, state, report, metadata) that will be part of the output. If empty, all fields will be part of the output.", @@ -3449,12 +3443,6 @@ "summary": "List all known processes", "operationId": "process-3-get-all", "parameters": [ - { - "type": "string", - "description": "Domain to act on", - "name": "domain", - "in": "query" - }, { "type": "string", "description": "Comma separated list of fields (config, state, report, metadata) that will be part of the output. If empty, all fields will be part of the output.", @@ -7476,6 +7464,9 @@ "type": "integer", "format": "int64" }, + "domain": { + "type": "string" + }, "exit_state": { "type": "string" }, @@ -7521,6 +7512,10 @@ "order": { "type": "string" }, + "pid": { + "type": "integer", + "format": "int32" + }, "progress": { "$ref": "#/definitions/api.Progress" }, diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 71677ebe..3b16105c 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -1522,6 +1522,8 @@ definitions: created_at: format: int64 type: integer + domain: + type: string exit_state: type: string exited_at: @@ -1553,6 +1555,9 @@ definitions: type: integer order: type: string + pid: + format: int32 + type: integer progress: $ref: '#/definitions/api.Progress' reconnect_seconds: @@ -3895,10 +3900,6 @@ paths: description: List of processes in the cluster operationId: cluster-3-get-all-processes parameters: - - description: Domain to act on - in: query - name: domain - type: string - description: Comma separated list of fields (config, state, report, metadata) that will be part of the output. If empty, all fields will be part of the output. @@ -5109,10 +5110,6 @@ paths: listed processes. operationId: process-3-get-all parameters: - - description: Domain to act on - in: query - name: domain - type: string - description: Comma separated list of fields (config, state, report, metadata) that will be part of the output. If empty, all fields will be part of the output. diff --git a/http/api/process.go b/http/api/process.go index 3738d40a..03c12a44 100644 --- a/http/api/process.go +++ b/http/api/process.go @@ -366,6 +366,7 @@ type ProcessState struct { LimitMode string `json:"limit_mode"` Resources ProcessUsage `json:"resources"` Command []string `json:"command"` + PID int32 `json:"pid" format:"int32"` } // Unmarshal converts a core ffmpeg process state to a state in API representation @@ -385,6 +386,7 @@ func (s *ProcessState) Unmarshal(state *app.State) { s.LimitMode = state.LimitMode s.Resources.Unmarshal(&state.Resources) s.Command = state.Command + s.PID = state.PID s.Progress.Unmarshal(&state.Progress) } diff --git a/process/process.go b/process/process.go index 77f8e456..ce0e077c 100644 --- a/process/process.go +++ b/process/process.go @@ -13,6 +13,7 @@ import ( "os/exec" "runtime" "sync" + "sync/atomic" "syscall" "time" "unicode/utf8" @@ -204,7 +205,7 @@ type process struct { args []string cmdArgs []string cmd *exec.Cmd - pid int32 + pid atomic.Int32 stdout io.ReadCloser state struct { state stateType @@ -265,6 +266,8 @@ func New(config Config) (Process, error) { resources: config.Resources, } + p.pid.Store(-1) + if p.resources == nil { return nil, fmt.Errorf("resources are required") } @@ -516,7 +519,7 @@ func (p *process) Status() Status { order := p.getOrder() s := Status{ - PID: p.pid, + PID: p.pid.Load(), State: state.String(), States: states, Order: order, @@ -707,6 +710,8 @@ func (p *process) start() error { return err } + p.pid.Store(int32(p.cmd.Process.Pid)) + // Start the stop timeout if enabled if p.timeout > time.Duration(0) { p.stopTimerLock.Lock() @@ -724,9 +729,7 @@ func (p *process) start() error { p.stopTimerLock.Unlock() } - p.pid = int32(p.cmd.Process.Pid) - - if proc, err := p.resources.Process(p.pid); err == nil { + if proc, err := p.resources.Process(p.pid.Load()); err == nil { p.limits.Start(proc) } @@ -1057,6 +1060,7 @@ func (p *process) waiter() { } p.setState(state) + p.pid.Store(-1) p.logger.Info().Log("Stopped") p.debuglogger.WithField("log", p.parser.Log()).Debug().Log("Stopped") diff --git a/restream/app/process.go b/restream/app/process.go index 501fc811..d1b99555 100644 --- a/restream/app/process.go +++ b/restream/app/process.go @@ -312,6 +312,7 @@ type State struct { LimitMode string // How the process is limited (hard or soft) Resources ProcessUsage // Current resource usage, include CPU, memory and GPU consumption Command []string // ffmpeg command line parameters + PID int32 // System process ID } type ProcessUsageCPU struct { diff --git a/restream/app/report.go b/restream/app/report.go index 3bf69500..a8dbf4ad 100644 --- a/restream/app/report.go +++ b/restream/app/report.go @@ -112,6 +112,7 @@ func (r *Report) MarshalParser() (parse.Report, []parse.ReportHistoryEntry) { type ReportHistorySearchResult struct { ProcessID string + Domain string Reference string ExitState string ExitedAt time.Time diff --git a/restream/task.go b/restream/task.go index 8fcee0bf..22d25b2b 100644 --- a/restream/task.go +++ b/restream/task.go @@ -243,6 +243,8 @@ func (t *task) State() (*app.State, error) { state.Progress.Input = assignConfigID(state.Progress.Input, t.config.Input) state.Progress.Output = assignConfigID(state.Progress.Output, t.config.Output) + state.PID = status.PID + return state, nil } @@ -312,6 +314,7 @@ func (t *task) SearchReportHistory(state string, from, to *time.Time) []app.Repo for _, f := range presult { result = append(result, app.ReportHistorySearchResult{ ProcessID: t.id, + Domain: t.domain, Reference: t.reference, ExitState: f.ExitState, CreatedAt: f.CreatedAt,