]> git.mxchange.org Git - friendica.git/blobdiff - src/Core/Worker.php
Fix notice in Util\Network
[friendica.git] / src / Core / Worker.php
index b8a9021d0fa1825f9be1bdc0393529422b2fd633..897a80111d67d4d6cc6c7309c8ee645ae3894d02 100644 (file)
@@ -4,14 +4,11 @@
  */
 namespace Friendica\Core;
 
-use Friendica\Core\Addon;
-use Friendica\Core\Config;
-use Friendica\Core\System;
+use dba;
 use Friendica\Database\DBM;
 use Friendica\Model\Process;
 use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Network;
-use dba;
 
 require_once 'include/dba.php';
 
@@ -44,7 +41,7 @@ class Worker
                self::$up_start = microtime(true);
 
                // At first check the maximum load. We shouldn't continue with a high load
-               if ($a->maxload_reached()) {
+               if ($a->isMaxLoadReached()) {
                        logger('Pre check: maximum load reached, quitting.', LOGGER_DEBUG);
                        return;
                }
@@ -78,7 +75,7 @@ class Worker
                }
 
                // Possibly there are too much database processes that block the system
-               if ($a->max_processes_reached()) {
+               if ($a->isMaxProcessesReached()) {
                        logger('Pre check: maximum processes reached, quitting.', LOGGER_DEBUG);
                        return;
                }
@@ -107,16 +104,16 @@ class Worker
                                }
 
                                // If possible we will fetch new jobs for this worker
-                               if (!$refetched && Lock::acquireLock('worker_process', 0)) {
+                               if (!$refetched && Lock::acquire('worker_process', 0)) {
                                        $stamp = (float)microtime(true);
                                        $refetched = self::findWorkerProcesses($passing_slow);
                                        self::$db_duration += (microtime(true) - $stamp);
-                                       Lock::releaseLock('worker_process');
+                                       Lock::release('worker_process');
                                }
                        }
 
                        // To avoid the quitting of multiple workers only one worker at a time will execute the check
-                       if (Lock::acquireLock('worker', 0)) {
+                       if (Lock::acquire('worker', 0)) {
                                $stamp = (float)microtime(true);
                                // Count active workers and compare them with a maximum value that depends on the load
                                if (self::tooMuchWorkers()) {
@@ -129,7 +126,7 @@ class Worker
                                        logger('Memory limit reached, quitting.', LOGGER_DEBUG);
                                        return;
                                }
-                               Lock::releaseLock('worker');
+                               Lock::release('worker');
                                self::$db_duration += (microtime(true) - $stamp);
                        }
 
@@ -144,7 +141,7 @@ class Worker
                if (Config::get('system', 'worker_daemon_mode', false)) {
                        self::IPCSetJobState(false);
                }
-               logger("Couldn't select a workerqueue entry, quitting.", LOGGER_DEBUG);
+               logger("Couldn't select a workerqueue entry, quitting process " . getmypid() . ".", LOGGER_DEBUG);
        }
 
        /**
@@ -206,7 +203,7 @@ class Worker
                }
 
                // Constantly check the number of parallel database processes
-               if ($a->max_processes_reached()) {
+               if ($a->isMaxProcessesReached()) {
                        logger("Max processes reached for process ".$mypid, LOGGER_DEBUG);
                        return false;
                }
@@ -312,7 +309,7 @@ class Worker
 
                $argc = count($argv);
 
-               $new_process_id = uniqid("wrk", true);
+               $new_process_id = System::processID("wrk");
 
                logger("Process ".$mypid." - Prio ".$queue["priority"]." - ID ".$queue["id"].": ".$funcname." ".$queue["parameter"]." - Process PID: ".$new_process_id);
 
@@ -355,7 +352,7 @@ class Worker
                $a->process_id = $old_process_id;
                unset($a->queue);
 
-               $duration = number_format(microtime(true) - $stamp, 3);
+               $duration = (microtime(true) - $stamp);
 
                self::$up_start = microtime(true);
 
@@ -600,7 +597,7 @@ class Worker
                                                ['id' => $entry["id"]]
                                        );
                                } else {
-                                       logger("Worker process ".$entry["pid"]." (".implode(" ", $argv).") now runs for ".round($duration)." of ".$max_duration." allowed minutes. That's okay.", LOGGER_DEBUG);
+                                       logger("Worker process ".$entry["pid"]." (".substr(json_encode($argv), 0, 50).") now runs for ".round($duration)." of ".$max_duration." allowed minutes. That's okay.", LOGGER_DEBUG);
                                }
                        }
                }
@@ -882,7 +879,7 @@ class Worker
                dba::close($r);
 
                $stamp = (float)microtime(true);
-               if (!Lock::acquireLock('worker_process')) {
+               if (!Lock::acquire('worker_process')) {
                        return false;
                }
                self::$lock_duration = (microtime(true) - $stamp);
@@ -891,7 +888,7 @@ class Worker
                $found = self::findWorkerProcesses($passing_slow);
                self::$db_duration += (microtime(true) - $stamp);
 
-               Lock::releaseLock('worker_process');
+               Lock::release('worker_process');
 
                if ($found) {
                        $r = dba::select('workerqueue', [], ['pid' => getmypid(), 'done' => false]);
@@ -1096,13 +1093,13 @@ class Worker
                }
 
                // If there is a lock then we don't have to check for too much worker
-               if (!Lock::acquireLock('worker', 0)) {
+               if (!Lock::acquire('worker', 0)) {
                        return true;
                }
 
                // If there are already enough workers running, don't fork another one
                $quit = self::tooMuchWorkers();
-               Lock::releaseLock('worker');
+               Lock::release('worker');
 
                if ($quit) {
                        return true;