]> git.mxchange.org Git - friendica.git/blobdiff - src/Core/Worker.php
Issue 11309: Check if a post is wanted
[friendica.git] / src / Core / Worker.php
index faa29717c145b05ae521d25bff671672524ffe63..5c23d64456cc873feef2220194314b381d1ac3cb 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * @copyright Copyright (C) 2010-2021, the Friendica project
+ * @copyright Copyright (C) 2010-2022, the Friendica project
  *
  * @license GNU AGPL version 3 or any later version
  *
@@ -52,7 +52,7 @@ class Worker
        private static $last_update;
        private static $state;
        private static $daemon_mode = null;
-       /** @var Worker\Entity\Process */
+       /** @var Process */
        private static $process;
 
        /**
@@ -754,7 +754,7 @@ class Worker
                                        }
 
                                        $stamp = (float)microtime(true);
-                                       $jobs = DBA::count('workerqueue', ["`done` AND `executed` > UTC_TIMESTAMP() - INTERVAL ? MINUTE", $interval]);
+                                       $jobs = DBA::count('workerqueue', ["`done` AND `executed` > ?", DateTimeFormat::utc('now - ' . $interval . ' minute')]);
                                        self::$db_duration += (microtime(true) - $stamp);
                                        self::$db_duration_stat += (microtime(true) - $stamp);
                                        $jobs_per_minute[$interval] = number_format($jobs / $interval, 0);
@@ -1183,22 +1183,22 @@ class Worker
                DBA::connect();
 
                DI::flushLogger();
-               $process = DI::process()->create($pid);
+               $process = DI::process()->create(getmypid(), basename(__FILE__));
 
                $cycles = 0;
-               while (!self::IPCJobsExists($pid) && (++$cycles < 100)) {
+               while (!self::IPCJobsExists($process->pid) && (++$cycles < 100)) {
                        usleep(10000);
                }
 
-               Logger::info('Worker spawned', ['pid' => $pid, 'wait_cycles' => $cycles]);
+               Logger::info('Worker spawned', ['pid' => $process->pid, 'wait_cycles' => $cycles]);
 
                self::processQueue($do_cron, $process);
 
                self::unclaimProcess($process);
 
-               self::IPCSetJobState(false, $pid);
+               self::IPCSetJobState(false, $process->pid);
                DI::process()->delete($process);
-               Logger::info('Worker ended', ['pid' => $pid]);
+               Logger::info('Worker ended', ['pid' => $process->pid]);
                exit();
        }
 
@@ -1378,8 +1378,9 @@ class Worker
         * Defers the current worker entry
         *
         * @return boolean had the entry been deferred?
+        * @throws \Exception
         */
-       public static function defer()
+       public static function defer(): bool
        {
                $queue = DI::app()->getQueue();
 
@@ -1387,7 +1388,6 @@ class Worker
                        return false;
                }
 
-               $retrial = $queue['retrial'];
                $id = $queue['id'];
                $priority = $queue['priority'];