]> git.mxchange.org Git - friendica.git/commitdiff
Don't create lock files if the process is called from the poller via the worker
authorMichael Vogel <icarus@dabo.de>
Mon, 7 Mar 2016 23:20:06 +0000 (00:20 +0100)
committerMichael Vogel <icarus@dabo.de>
Mon, 7 Mar 2016 23:20:06 +0000 (00:20 +0100)
include/cron.php
include/cronhooks.php
include/discover_poco.php
include/onepoll.php
include/ostatus.php
include/pubsubpublish.php
include/queue.php
include/update_gcontact.php

index 3acf711dd163056234b822a1eb27f39387108a7b..6143281710feed8e33a175a385caa56f53c63440 100644 (file)
@@ -40,15 +40,33 @@ function cron_run(&$argv, &$argc){
        load_config('config');
        load_config('system');
 
-       $maxsysload = intval(get_config('system','maxloadavg'));
-       if($maxsysload < 1)
-               $maxsysload = 50;
-
-       $load = current_load();
-       if($load) {
-               if(intval($load) > $maxsysload) {
-                       logger('system: load ' . $load . ' too high. cron deferred to next scheduled run.');
-                       return;
+       // Don't check this stuff if the function is called by the poller
+       if (App::callstack() != "poller_run") {
+               $maxsysload = intval(get_config('system','maxloadavg'));
+               if($maxsysload < 1)
+                       $maxsysload = 50;
+
+               $load = current_load();
+               if($load) {
+                       if(intval($load) > $maxsysload) {
+                               logger('system: load '.$load.' too high. cron deferred to next scheduled run.');
+                               return;
+                       }
+               }
+
+               $lockpath = get_lockpath();
+               if ($lockpath != '') {
+                       $pidfile = new pidfile($lockpath, 'cron');
+                       if($pidfile->is_already_running()) {
+                               logger("cron: Already running");
+                               if ($pidfile->running_time() > 9*60) {
+                                       $pidfile->kill();
+                                       logger("cron: killed stale process");
+                                       // Calling a new instance
+                                       proc_run('php','include/cron.php');
+                               }
+                               exit;
+                       }
                }
        }
 
@@ -66,23 +84,6 @@ function cron_run(&$argv, &$argc){
                }
        }
 
-       $lockpath = get_lockpath();
-       if ($lockpath != '') {
-               $pidfile = new pidfile($lockpath, 'cron');
-               if($pidfile->is_already_running()) {
-                       logger("cron: Already running");
-                       if ($pidfile->running_time() > 9*60) {
-                               $pidfile->kill();
-                               logger("cron: killed stale process");
-                               // Calling a new instance
-                               proc_run('php','include/cron.php');
-                       }
-                       exit;
-               }
-       }
-
-
-
        $a->set_baseurl(get_config('system','url'));
 
        load_hooks();
index 8c70008e453c913e9318184ed859e161ed68eb6a..71cb0fb7b2f44a72caad66ecde5eb29f84cbc6c2 100644 (file)
@@ -24,15 +24,33 @@ function cronhooks_run(&$argv, &$argc){
        load_config('config');
        load_config('system');
 
-       $maxsysload = intval(get_config('system','maxloadavg'));
-       if($maxsysload < 1)
-               $maxsysload = 50;
-
-       $load = current_load();
-       if($load) {
-               if(intval($load) > $maxsysload) {
-                       logger('system: load ' . $load . ' too high. Cronhooks deferred to next scheduled run.');
-                       return;
+       // Don't check this stuff if the function is called by the poller
+       if (App::callstack() != "poller_run") {
+               $maxsysload = intval(get_config('system','maxloadavg'));
+               if($maxsysload < 1)
+                       $maxsysload = 50;
+
+               $load = current_load();
+               if($load) {
+                       if(intval($load) > $maxsysload) {
+                               logger('system: load ' . $load . ' too high. Cronhooks deferred to next scheduled run.');
+                               return;
+                       }
+               }
+
+               $lockpath = get_lockpath();
+               if ($lockpath != '') {
+                       $pidfile = new pidfile($lockpath, 'cronhooks');
+                       if($pidfile->is_already_running()) {
+                               logger("cronhooks: Already running");
+                               if ($pidfile->running_time() > 19*60) {
+                                       $pidfile->kill();
+                                       logger("cronhooks: killed stale process");
+                                       // Calling a new instance
+                                       proc_run('php','include/cronhooks.php');
+                               }
+                               exit;
+                       }
                }
        }
 
@@ -50,21 +68,6 @@ function cronhooks_run(&$argv, &$argc){
                }
        }
 
-       $lockpath = get_lockpath();
-       if ($lockpath != '') {
-               $pidfile = new pidfile($lockpath, 'cronhooks');
-               if($pidfile->is_already_running()) {
-                       logger("cronhooks: Already running");
-                       if ($pidfile->running_time() > 19*60) {
-                               $pidfile->kill();
-                               logger("cronhooks: killed stale process");
-                               // Calling a new instance
-                               proc_run('php','include/cronhooks.php');
-                       }
-                       exit;
-               }
-       }
-
        $a->set_baseurl(get_config('system','url'));
 
        load_hooks();
index a8f670334b5d66a00d8fc5022d584472dfa85b80..550c9897be9fb3daee861cdc9561ad70997486f0 100644 (file)
@@ -25,15 +25,18 @@ function discover_poco_run(&$argv, &$argc){
        load_config('config');
        load_config('system');
 
-       $maxsysload = intval(get_config('system','maxloadavg'));
-       if($maxsysload < 1)
-               $maxsysload = 50;
-
-       $load = current_load();
-       if($load) {
-               if(intval($load) > $maxsysload) {
-                       logger('system: load ' . $load . ' too high. discover_poco deferred to next scheduled run.');
-                       return;
+       // Don't check this stuff if the function is called by the poller
+       if (App::callstack() != "poller_run") {
+               $maxsysload = intval(get_config('system','maxloadavg'));
+               if($maxsysload < 1)
+                       $maxsysload = 50;
+
+               $load = current_load();
+               if($load) {
+                       if(intval($load) > $maxsysload) {
+                               logger('system: load '.$load.' too high. discover_poco deferred to next scheduled run.');
+                               return;
+                       }
                }
        }
 
@@ -50,19 +53,22 @@ function discover_poco_run(&$argv, &$argc){
        } else
                die("Unknown or missing parameter ".$argv[1]."\n");
 
-       $lockpath = get_lockpath();
-       if ($lockpath != '') {
-               $pidfile = new pidfile($lockpath, 'discover_poco'.$mode.urlencode($search));
-               if($pidfile->is_already_running()) {
-                       logger("discover_poco: Already running");
-                       if ($pidfile->running_time() > 19*60) {
-                               $pidfile->kill();
-                               logger("discover_poco: killed stale process");
-                               // Calling a new instance
-                               if ($mode == 0)
-                                       proc_run('php','include/discover_poco.php');
+       // Don't check this stuff if the function is called by the poller
+       if (App::callstack() != "poller_run") {
+               $lockpath = get_lockpath();
+               if ($lockpath != '') {
+                       $pidfile = new pidfile($lockpath, 'discover_poco'.$mode.urlencode($search));
+                       if($pidfile->is_already_running()) {
+                               logger("discover_poco: Already running");
+                               if ($pidfile->running_time() > 19*60) {
+                                       $pidfile->kill();
+                                       logger("discover_poco: killed stale process");
+                                       // Calling a new instance
+                                       if ($mode == 0)
+                                               proc_run('php','include/discover_poco.php');
+                               }
+                               exit;
                        }
-                       exit;
                }
        }
 
index 6fb191f73da534dff3230ac9692848a9dd897d68..8b91070dcce453137d752c92c695a0acdcc7dfbc 100644 (file)
@@ -60,16 +60,19 @@ function onepoll_run(&$argv, &$argc){
                return;
        }
 
-       $lockpath = get_lockpath();
-       if ($lockpath != '') {
-               $pidfile = new pidfile($lockpath, 'onepoll'.$contact_id);
-               if ($pidfile->is_already_running()) {
-                       logger("onepoll: Already running for contact ".$contact_id);
-                       if ($pidfile->running_time() > 9*60) {
-                               $pidfile->kill();
-                               logger("killed stale process");
+       // Don't check this stuff if the function is called by the poller
+       if (App::callstack() != "poller_run") {
+               $lockpath = get_lockpath();
+               if ($lockpath != '') {
+                       $pidfile = new pidfile($lockpath, 'onepoll'.$contact_id);
+                       if ($pidfile->is_already_running()) {
+                               logger("onepoll: Already running for contact ".$contact_id);
+                               if ($pidfile->running_time() > 9*60) {
+                                       $pidfile->kill();
+                                       logger("killed stale process");
+                               }
+                               exit;
                        }
-                       exit;
                }
        }
 
index 54b70e6d6c8482c1285aec9a5f6bfa26f4dda5e9..ac13ce6bc8521d643f7a3f72f1146bbf9be207a9 100644 (file)
@@ -954,16 +954,21 @@ function ostatus_completion($conversation_url, $uid, $item = array(), $self = ""
                if (isset($single_conv->actor->url))
                        $actor = $single_conv->actor->url;
 
-               $contact = q("SELECT `id`, `rel` FROM `contact` WHERE `uid` = %d AND `nurl` = '%s' AND `network` != '%s'",
+               $contact = q("SELECT `id`, `rel`, `network` FROM `contact` WHERE `uid` = %d AND `nurl` = '%s' AND `network` != '%s'",
                                $uid, normalise_link($actor), NETWORK_STATUSNET);
 
-               if (count($contact)) {
+               if (!$contact)
+                       $contact = q("SELECT `id`, `rel`, `network` FROM `contact` WHERE `uid` = %d AND `alias` IN ('%s', '%s') AND `network` != '%s'",
+                                       $uid, $actor, normalise_link($actor), NETWORK_STATUSNET);
+
+               if ($contact) {
                        logger("Found contact for url ".$actor, LOGGER_DEBUG);
                        $contact_id = $contact[0]["id"];
+                       $network = $contact[0]["network"];
 
                        $not_following = !in_array($contact[0]["rel"], array(CONTACT_IS_SHARING, CONTACT_IS_FRIEND));
                } else {
-                       logger("No contact found for url ".$actor, LOGGER_DEBUG);
+                       logger("No contact found for user ".$uid." and url ".$actor, LOGGER_DEBUG);
 
                        // Adding a global contact
                        /// @TODO Use this data for the post
@@ -972,18 +977,19 @@ function ostatus_completion($conversation_url, $uid, $item = array(), $self = ""
                        logger("Global contact ".$global_contact_id." found for url ".$actor, LOGGER_DEBUG);
 
                        $contact_id = $parent["contact-id"];
+                       $network = NETWORK_OSTATUS;
 
                        $not_following = true;
                }
 
                // Do we only want to import threads that were started by our contacts?
                if ($not_following AND $new_parent AND get_config('system','ostatus_full_threads')) {
-                       logger("Don't import uri ".$first_id." because we don't follow the person ".$actor, LOGGER_DEBUG);
+                       logger("Don't import uri ".$first_id." because user ".$uid." doesn't follow the person ".$actor, LOGGER_DEBUG);
                        continue;
                }
 
                $arr = array();
-               $arr["network"] = NETWORK_OSTATUS;
+               $arr["network"] = $network;
                $arr["uri"] = $single_conv->id;
                $arr["plink"] = $plink;
                $arr["uid"] = $uid;
index 0ac50aaaa76a44e94a4839ce977abbb0d0fc0293..e7a55f5f09f37b682af45b5c11e3129c8011d452 100644 (file)
@@ -79,18 +79,21 @@ function pubsubpublish_run(&$argv, &$argc){
        load_config('config');
        load_config('system');
 
-       $lockpath = get_lockpath();
-       if ($lockpath != '') {
-               $pidfile = new pidfile($lockpath, 'pubsubpublish');
-               if($pidfile->is_already_running()) {
-                       logger("Already running");
-                       if ($pidfile->running_time() > 9*60) {
-                               $pidfile->kill();
-                               logger("killed stale process");
-                               // Calling a new instance
-                               proc_run('php',"include/pubsubpublish.php");
+       // Don't check this stuff if the function is called by the poller
+       if (App::callstack() != "poller_run") {
+               $lockpath = get_lockpath();
+               if ($lockpath != '') {
+                       $pidfile = new pidfile($lockpath, 'pubsubpublish');
+                       if($pidfile->is_already_running()) {
+                               logger("Already running");
+                               if ($pidfile->running_time() > 9*60) {
+                                       $pidfile->kill();
+                                       logger("killed stale process");
+                                       // Calling a new instance
+                                       proc_run('php',"include/pubsubpublish.php");
+                               }
+                               return;
                        }
-                       return;
                }
        }
 
index 1525ca3abf561cd363c9cad5d9d3158b49f75b32..157fc88d944a350b747a731ef0756f1117d432cb 100644 (file)
@@ -28,18 +28,21 @@ function queue_run(&$argv, &$argc){
        load_config('config');
        load_config('system');
 
-       $lockpath = get_lockpath();
-       if ($lockpath != '') {
-               $pidfile = new pidfile($lockpath, 'queue');
-               if($pidfile->is_already_running()) {
-                       logger("queue: Already running");
-                       if ($pidfile->running_time() > 9*60) {
-                               $pidfile->kill();
-                               logger("queue: killed stale process");
-                               // Calling a new instance
-                               proc_run('php',"include/queue.php");
+       // Don't check this stuff if the function is called by the poller
+       if (App::callstack() != "poller_run") {
+               $lockpath = get_lockpath();
+               if ($lockpath != '') {
+                       $pidfile = new pidfile($lockpath, 'queue');
+                       if($pidfile->is_already_running()) {
+                               logger("queue: Already running");
+                               if ($pidfile->running_time() > 9*60) {
+                                       $pidfile->kill();
+                                       logger("queue: killed stale process");
+                                       // Calling a new instance
+                                       proc_run('php',"include/queue.php");
+                               }
+                               return;
                        }
-                       return;
                }
        }
 
index b5ea30a0a4d8803bedb8c0a80dc02ee3d977d283..b7bf25aa242ae16bdf08bb63a66bcff0e26c7ba0 100644 (file)
@@ -37,16 +37,19 @@ function update_gcontact_run(&$argv, &$argc){
                return;
        }
 
-       $lockpath = get_lockpath();
-       if ($lockpath != '') {
-               $pidfile = new pidfile($lockpath, 'update_gcontact'.$contact_id);
-               if ($pidfile->is_already_running()) {
-                       logger("update_gcontact: Already running for contact ".$contact_id);
-                       if ($pidfile->running_time() > 9*60) {
-                               $pidfile->kill();
-                               logger("killed stale process");
+       // Don't check this stuff if the function is called by the poller
+       if (App::callstack() != "poller_run") {
+               $lockpath = get_lockpath();
+               if ($lockpath != '') {
+                       $pidfile = new pidfile($lockpath, 'update_gcontact'.$contact_id);
+                       if ($pidfile->is_already_running()) {
+                               logger("update_gcontact: Already running for contact ".$contact_id);
+                               if ($pidfile->running_time() > 9*60) {
+                                       $pidfile->kill();
+                                       logger("killed stale process");
+                               }
+                               exit;
                        }
-                       exit;
                }
        }