]> git.mxchange.org Git - friendica.git/commitdiff
Fixup command argument
authorPhilipp <admin@philipp.info>
Sun, 31 Oct 2021 13:31:02 +0000 (14:31 +0100)
committerPhilipp <admin@philipp.info>
Fri, 5 Nov 2021 19:52:31 +0000 (20:52 +0100)
src/Core/Worker.php
src/Core/Worker/Entity/Process.php
src/Core/Worker/Factory/Process.php
src/Core/Worker/Repository/Process.php

index cee1c655210fb0b296fa9d7d5a076acabcfd0f11..d7133c0b7a1b154ccd6ef3d160c84e7d61afc4fd 100644 (file)
@@ -846,7 +846,7 @@ class Worker
        private static function activeWorkers()
        {
                $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_count += (microtime(true) - $stamp);
                return $count;
index 57e3853382acb55a03a8c8be071e2c4a4bb6e34d..7161f9ca46556b076f3230e80a63bd80d8d55709 100644 (file)
@@ -30,17 +30,4 @@ class Process extends BaseEntity
                $this->command = $command;
                $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')));
-       }
 }
index 38985983b2aef5065245f799cacac881445eb4a8..1b66906899673b8fa4a07171e5ee8ed67ab7f71a 100644 (file)
@@ -20,16 +20,13 @@ class Process extends BaseFactory implements ICanCreateFromTableRow
        /**
         * Creates a new process entry 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
        {
-               $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 1);
-
-               $command = basename($trace[0]['file']);
-
                return $this->createFromTableRow([
                        'pid'     => $pid,
                        'command' => $command,
index 8fe1d709b07cd1da527f13542be316674498c121..d14121b973dd5391466e6ea81ed667fdc6f37da3 100644 (file)
@@ -59,11 +59,16 @@ class Process extends BaseRepository
                try {
                        $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->insert(static::$table_name, [
-                                       'pid' => $newProcess->pid,
+                                       'pid'     => $newProcess->pid,
                                        'command' => $newProcess->command,
                                        'created' => $newProcess->created->format(DateTimeFormat::MYSQL)
                                ])) {
@@ -115,4 +120,22 @@ class Process extends BaseRepository
                        $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);
+               }
+       }
 }