From c2b5eb2838df2d420bb59041fbc9497186e0de4f Mon Sep 17 00:00:00 2001 From: Philipp Date: Mon, 1 Nov 2021 13:54:18 +0100 Subject: [PATCH] Improve repository usage --- bin/worker.php | 2 +- src/Core/Worker.php | 2 +- src/Core/Worker/Repository/Process.php | 16 ++++++---------- 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/bin/worker.php b/bin/worker.php index 13018b49d9..877f1333e0 100755 --- a/bin/worker.php +++ b/bin/worker.php @@ -81,7 +81,7 @@ if ($spawn) { $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); diff --git a/src/Core/Worker.php b/src/Core/Worker.php index bdc184d2f1..8dd1ece8e5 100644 --- a/src/Core/Worker.php +++ b/src/Core/Worker.php @@ -1183,7 +1183,7 @@ class Worker DBA::connect(); DI::flushLogger(); - $process = DI::process()->create(getmypid()); + $process = DI::process()->create(getmypid(), basename(__FILE__)); $cycles = 0; while (!self::IPCJobsExists($process->pid) && (++$cycles < 100)) { diff --git a/src/Core/Worker/Repository/Process.php b/src/Core/Worker/Repository/Process.php index d14121b973..1e91d867fb 100644 --- a/src/Core/Worker/Repository/Process.php +++ b/src/Core/Worker/Repository/Process.php @@ -47,11 +47,12 @@ class Process extends BaseRepository /** * Starts and Returns the process for a given PID * - * @param int $pid + * @param int $pid + * @param string $command * * @return Entity\Process */ - public function create(int $pid): Entity\Process + public function create(int $pid, string $command): Entity\Process { // Cleanup inactive process $this->deleteInactive(); @@ -59,11 +60,6 @@ class Process extends BaseRepository try { $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); if (!$this->db->exists('process', ['pid' => $pid])) { @@ -114,10 +110,10 @@ class Process extends BaseRepository } } $this->db->close($processes); - } catch (\Exception $exception) { - throw new ProcessPersistenceException('Cannot delete inactive process', $exception); - } finally { $this->db->commit(); + } catch (\Exception $exception) { + $this->db->rollback(); + throw new ProcessPersistenceException('Cannot delete inactive process', $exception); } }