]> git.mxchange.org Git - friendica.git/commitdiff
Some more improvements
authorMichael <heluecht@pirati.ca>
Sun, 5 Nov 2017 15:28:55 +0000 (15:28 +0000)
committerMichael <heluecht@pirati.ca>
Sun, 5 Nov 2017 15:28:55 +0000 (15:28 +0000)
boot.php
include/poller.php
src/Core/Worker.php

index d8659805dc4e1b70f8b691f7f882f990033657d4..35c37d715ea07909bb5f8f0623ec3dd3571d0fc2 100644 (file)
--- a/boot.php
+++ b/boot.php
@@ -22,7 +22,6 @@ require_once(__DIR__ . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'a
 
 use Friendica\App;
 use Friendica\Core\System;
-use Friendica\Core\Worker;
 use Friendica\Core\Config;
 use Friendica\Util\Lock;
 
@@ -1030,6 +1029,18 @@ function get_max_import_size() {
        return ((x($a->config, 'max_import_size')) ? $a->config['max_import_size'] : 0 );
 }
 
+/**
+ * @brief compatibilty wrapper for Worker::add function
+ *
+ * @param (integer|array) priority or parameter array, $cmd atrings are deprecated and are ignored
+ *
+ * @return boolean "false" if proc_run couldn't be executed
+ */
+function proc_run() {
+       $proc_args = func_get_args();
+       call_user_func_array('Friendica\Core\Worker::add', $proc_args);
+}
+
 function current_theme() {
        $app_base_themes = array('duepuntozero', 'dispy', 'quattro');
 
index 6eb04971c39844e4dacfac370b75da374653a397..3f6290a98f2b71140571070c767865bba37af6aa 100644 (file)
@@ -42,17 +42,7 @@ function poller_run($argv, $argc) {
 
        load_hooks();
 
-       // At first check the maximum load. We shouldn't continue with a high load
-       if ($a->maxload_reached()) {
-               logger('Pre check: maximum load reached, quitting.', LOGGER_DEBUG);
-               return;
-       }
-
-       // We now start the process. This is done after the load check since this could increase the load.
-       $a->start_process();
-
        $run_cron = (($argc <= 1) || ($argv[1] != "no_cron"));
-
        Worker::processQueue($run_cron);
        return;
 }
index 5964f44046dd99b9e2ec343dac546f391790a10c..ac5c04a2719705141dc50d9971af555a3041faf8 100644 (file)
@@ -4,6 +4,7 @@ namespace Friendica\Core;
 use Friendica\App;
 use Friendica\Core\System;
 use Friendica\Core\Config;
+use Friendica\Core\Worker;
 use Friendica\Util\Lock;
 
 use dba;
@@ -34,6 +35,15 @@ 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()) {
+                       logger('Pre check: maximum load reached, quitting.', LOGGER_DEBUG);
+                       return;
+               }
+
+               // We now start the process. This is done after the load check since this could increase the load.
+               $a->start_process();
+
                // Kill stale processes every 5 minutes
                $last_cleanup = Config::get('system', 'poller_last_cleaned', 0);
                if (time() > ($last_cleanup + 300)) {
@@ -589,8 +599,7 @@ class Worker {
                        // Are there fewer workers running as possible? Then fork a new one.
                        if (!Config::get("system", "worker_dont_fork") && ($queues > ($active + 1)) && ($entries > 1)) {
                                logger("Active workers: ".$active."/".$queues." Fork a new worker.", LOGGER_DEBUG);
-                               $args = array("include/poller.php", "no_cron");
-                               get_app()->proc_run($args);
+                               self::spawnWorker();
                        }
                }
 
@@ -603,7 +612,7 @@ class Worker {
         * @return integer Number of active poller processes
         */
        private static function activeWorkers() {
-               $workers = q("SELECT COUNT(*) AS `processes` FROM `process` WHERE `command` = 'poller.php'");
+               $workers = q("SELECT COUNT(*) AS `processes` FROM `process` WHERE `command` = 'Worker.php'");
 
                return $workers[0]["processes"];
        }
@@ -821,9 +830,7 @@ class Worker {
                        self::runCron();
 
                        logger('Call poller', LOGGER_DEBUG);
-
-                       $args = array("include/poller.php", "no_cron");
-                       get_app()->proc_run($args);
+                       self::spawnWorker();
                        return;
                }
 
@@ -871,6 +878,11 @@ class Worker {
                self::killStaleWorkers();
        }
 
+       public static function spawnWorker() {
+               $args = array("include/poller.php", "no_cron");
+               get_app()->proc_run($args);
+       }
+
        /**
         * @brief Adds tasks to the worker queue
         *
@@ -973,8 +985,7 @@ class Worker {
                }
 
                // Now call the poller to execute the jobs that we just added to the queue
-               $args = array("include/poller.php", "no_cron");
-               get_app()->proc_run($args);
+               self::spawnWorker();
 
                return true;
        }