Improve repository usage
This commit is contained in:
parent
7c6554451e
commit
c2b5eb2838
3 changed files with 8 additions and 12 deletions
|
@ -81,7 +81,7 @@ if ($spawn) {
|
||||||
|
|
||||||
$run_cron = !array_key_exists('n', $options) && !array_key_exists('no_cron', $options);
|
$run_cron = !array_key_exists('n', $options) && !array_key_exists('no_cron', $options);
|
||||||
|
|
||||||
$process = DI::process()->create(getmypid());
|
$process = DI::process()->create(getmypid(), basename(__FILE__));
|
||||||
|
|
||||||
Worker::processQueue($run_cron, $process);
|
Worker::processQueue($run_cron, $process);
|
||||||
|
|
||||||
|
|
|
@ -1183,7 +1183,7 @@ class Worker
|
||||||
DBA::connect();
|
DBA::connect();
|
||||||
|
|
||||||
DI::flushLogger();
|
DI::flushLogger();
|
||||||
$process = DI::process()->create(getmypid());
|
$process = DI::process()->create(getmypid(), basename(__FILE__));
|
||||||
|
|
||||||
$cycles = 0;
|
$cycles = 0;
|
||||||
while (!self::IPCJobsExists($process->pid) && (++$cycles < 100)) {
|
while (!self::IPCJobsExists($process->pid) && (++$cycles < 100)) {
|
||||||
|
|
|
@ -47,11 +47,12 @@ class Process extends BaseRepository
|
||||||
/**
|
/**
|
||||||
* Starts and Returns the process for a given PID
|
* Starts and Returns the process 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
|
||||||
{
|
{
|
||||||
// Cleanup inactive process
|
// Cleanup inactive process
|
||||||
$this->deleteInactive();
|
$this->deleteInactive();
|
||||||
|
@ -59,11 +60,6 @@ class Process extends BaseRepository
|
||||||
try {
|
try {
|
||||||
$this->db->transaction();
|
$this->db->transaction();
|
||||||
|
|
||||||
$trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
|
|
||||||
$last = $trace[count($trace) - 1];
|
|
||||||
|
|
||||||
$command = strtolower(basename($last['file']));
|
|
||||||
|
|
||||||
$newProcess = $this->factory->create($pid, $command);
|
$newProcess = $this->factory->create($pid, $command);
|
||||||
|
|
||||||
if (!$this->db->exists('process', ['pid' => $pid])) {
|
if (!$this->db->exists('process', ['pid' => $pid])) {
|
||||||
|
@ -114,10 +110,10 @@ class Process extends BaseRepository
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$this->db->close($processes);
|
$this->db->close($processes);
|
||||||
} catch (\Exception $exception) {
|
|
||||||
throw new ProcessPersistenceException('Cannot delete inactive process', $exception);
|
|
||||||
} finally {
|
|
||||||
$this->db->commit();
|
$this->db->commit();
|
||||||
|
} catch (\Exception $exception) {
|
||||||
|
$this->db->rollback();
|
||||||
|
throw new ProcessPersistenceException('Cannot delete inactive process', $exception);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue