mirror of
https://github.com/friendica/friendica
synced 2024-12-23 15:20:17 +00:00
Fixup command argument
This commit is contained in:
parent
38f70cc55a
commit
7637ae1dcc
4 changed files with 29 additions and 22 deletions
|
@ -846,7 +846,7 @@ class Worker
|
||||||
private static function activeWorkers()
|
private static function activeWorkers()
|
||||||
{
|
{
|
||||||
$stamp = (float)microtime(true);
|
$stamp = (float)microtime(true);
|
||||||
$count = DBA::count('process', ['command' => 'Worker.php']);
|
$count = DI::process()->countCommand('Worker.php');
|
||||||
self::$db_duration += (microtime(true) - $stamp);
|
self::$db_duration += (microtime(true) - $stamp);
|
||||||
self::$db_duration_count += (microtime(true) - $stamp);
|
self::$db_duration_count += (microtime(true) - $stamp);
|
||||||
return $count;
|
return $count;
|
||||||
|
|
|
@ -30,17 +30,4 @@ class Process extends BaseEntity
|
||||||
$this->command = $command;
|
$this->command = $command;
|
||||||
$this->created = $created;
|
$this->created = $created;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a new Process with the given PID
|
|
||||||
*
|
|
||||||
* @param int $pid
|
|
||||||
*
|
|
||||||
* @return $this
|
|
||||||
* @throws \Exception
|
|
||||||
*/
|
|
||||||
public function withPid(int $pid): Process
|
|
||||||
{
|
|
||||||
return new static($pid, $this->command, new DateTime('now', new \DateTimeZone('URC')));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,15 +21,12 @@ class Process extends BaseFactory implements ICanCreateFromTableRow
|
||||||
* Creates a new process entry for a given PID
|
* Creates a new process entry for a given PID
|
||||||
*
|
*
|
||||||
* @param int $pid
|
* @param int $pid
|
||||||
|
* @param string $command
|
||||||
*
|
*
|
||||||
* @return Entity\Process
|
* @return Entity\Process
|
||||||
*/
|
*/
|
||||||
public function create(int $pid): Entity\Process
|
public function create(int $pid, string $command): Entity\Process
|
||||||
{
|
{
|
||||||
$trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 1);
|
|
||||||
|
|
||||||
$command = basename($trace[0]['file']);
|
|
||||||
|
|
||||||
return $this->createFromTableRow([
|
return $this->createFromTableRow([
|
||||||
'pid' => $pid,
|
'pid' => $pid,
|
||||||
'command' => $command,
|
'command' => $command,
|
||||||
|
|
|
@ -59,7 +59,12 @@ class Process extends BaseRepository
|
||||||
try {
|
try {
|
||||||
$this->db->transaction();
|
$this->db->transaction();
|
||||||
|
|
||||||
$newProcess = $this->factory->create($pid);
|
$trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
|
||||||
|
$last = $trace[count($trace) - 1];
|
||||||
|
|
||||||
|
$command = strtolower(basename($last['file']));
|
||||||
|
|
||||||
|
$newProcess = $this->factory->create($pid, $command);
|
||||||
|
|
||||||
if (!$this->db->exists('process', ['pid' => $pid])) {
|
if (!$this->db->exists('process', ['pid' => $pid])) {
|
||||||
if (!$this->db->insert(static::$table_name, [
|
if (!$this->db->insert(static::$table_name, [
|
||||||
|
@ -115,4 +120,22 @@ class Process extends BaseRepository
|
||||||
$this->db->commit();
|
$this->db->commit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the number of processes with a given command
|
||||||
|
*
|
||||||
|
* @param string $command
|
||||||
|
*
|
||||||
|
* @return int Number of processes
|
||||||
|
*
|
||||||
|
* @throws ProcessPersistenceException
|
||||||
|
*/
|
||||||
|
public function countCommand(string $command): int
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
return $this->count(['command' => strtolower($command)]);
|
||||||
|
} catch (\Exception $exception) {
|
||||||
|
throw new ProcessPersistenceException('Cannot count ', $exception);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue