mirror of https://github.com/MISP/MISP
fix: issues when worker is stopped, allow null pid and user in worker class
parent
766f559852
commit
89c39270e4
|
@ -6,7 +6,7 @@ App::uses('Model', 'Model');
|
|||
|
||||
class Worker implements JsonSerializable
|
||||
{
|
||||
/** @var integer */
|
||||
/** @var integer|null */
|
||||
private $pid;
|
||||
|
||||
/** @var string */
|
||||
|
@ -15,7 +15,7 @@ class Worker implements JsonSerializable
|
|||
/**
|
||||
* OS user
|
||||
*
|
||||
* @var string
|
||||
* @var string|null
|
||||
*/
|
||||
private $user;
|
||||
|
||||
|
@ -67,7 +67,7 @@ class Worker implements JsonSerializable
|
|||
];
|
||||
}
|
||||
|
||||
public function pid(): int
|
||||
public function pid(): ?int
|
||||
{
|
||||
return $this->pid;
|
||||
}
|
||||
|
@ -77,7 +77,7 @@ class Worker implements JsonSerializable
|
|||
return $this->queue;
|
||||
}
|
||||
|
||||
public function user(): string
|
||||
public function user(): ?string
|
||||
{
|
||||
return $this->user;
|
||||
}
|
||||
|
|
|
@ -295,14 +295,17 @@ class BackgroundJobsTool
|
|||
|
||||
foreach ($procs as $proc) {
|
||||
if ($proc->offsetGet('group') === self::MISP_WORKERS_PROCESS_GROUP) {
|
||||
$workers[] = new Worker([
|
||||
'pid' => $proc->offsetGet('pid'),
|
||||
'queue' => explode("_", $proc->offsetGet('name'))[0],
|
||||
'user' => trim(shell_exec(sprintf("ps -o uname= -p %s", (int) $proc->offsetGet('pid')))),
|
||||
'createdAt' => $proc->offsetGet('start'),
|
||||
'updatedAt' => $proc->offsetGet('now'),
|
||||
'status' => $this->convertProcessStatus($proc->offsetGet('state'))
|
||||
]);
|
||||
if ($proc->offsetGet('pid') > 0) {
|
||||
$user = trim(shell_exec(sprintf("ps -o uname='' -p %s", (int) $proc->offsetGet('pid'))) ?? '');
|
||||
$workers[] = new Worker([
|
||||
'pid' => $proc->offsetGet('pid'),
|
||||
'queue' => explode("_", $proc->offsetGet('name'))[0],
|
||||
'user' => $user,
|
||||
'createdAt' => $proc->offsetGet('start'),
|
||||
'updatedAt' => $proc->offsetGet('now'),
|
||||
'status' => $this->convertProcessStatus($proc->offsetGet('state'))
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue