]> git.mxchange.org Git - friendica.git/commitdiff
Improve repository usage
authorPhilipp <admin@philipp.info>
Mon, 1 Nov 2021 12:54:18 +0000 (13:54 +0100)
committerPhilipp <admin@philipp.info>
Fri, 5 Nov 2021 19:52:34 +0000 (20:52 +0100)
bin/worker.php
src/Core/Worker.php
src/Core/Worker/Repository/Process.php

index 13018b49d97ac915634a59c767a1543761fa0818..877f1333e040d37fd1e221afe4c42e5e58082214 100755 (executable)
@@ -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);
 
index bdc184d2f1524c76ca92a172d4d6feda6c974d7e..8dd1ece8e5e41ada1cc0bfb4a9ed85de59ce219a 100644 (file)
@@ -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)) {
index d14121b973dd5391466e6ea81ed667fdc6f37da3..1e91d867fb3e1e8b2a3106f2c3863c47e8c854ac 100644 (file)
@@ -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);
+                       $this->db->commit();
                } catch (\Exception $exception) {
+                       $this->db->rollback();
                        throw new ProcessPersistenceException('Cannot delete inactive process', $exception);
-               } finally {
-                       $this->db->commit();
                }
        }