]> git.mxchange.org Git - friendica.git/blobdiff - include/cron.php
Merge pull request #3902 from annando/worker-space
[friendica.git] / include / cron.php
index 8bc83a37214abf7c924afd302b8c1e75dde41e53..01989826da28716ea14ddeecdd3719824e18464b 100644 (file)
@@ -1,5 +1,8 @@
 <?php
-use \Friendica\Core\Config;
+
+use Friendica\Core\Config;
+use Friendica\Core\Worker;
+use Friendica\Database\DBM;
 
 function cron_run(&$argv, &$argc){
        global $a;
@@ -12,9 +15,9 @@ function cron_run(&$argv, &$argc){
                return;
        }
 
-       $last = get_config('system', 'last_cron');
+       $last = Config::get('system', 'last_cron');
 
-       $poll_interval = intval(get_config('system', 'cron_interval'));
+       $poll_interval = intval(Config::get('system', 'cron_interval'));
        if (! $poll_interval) {
                $poll_interval = 10;
        }
@@ -30,57 +33,57 @@ function cron_run(&$argv, &$argc){
        logger('cron: start');
 
        // run queue delivery process in the background
-       proc_run(PRIORITY_NEGLIGIBLE, "include/queue.php");
+       Worker::add(PRIORITY_NEGLIGIBLE, "queue");
 
        // run the process to discover global contacts in the background
-       proc_run(PRIORITY_LOW, "include/discover_poco.php");
+       Worker::add(PRIORITY_LOW, "discover_poco");
 
        // run the process to update locally stored global contacts in the background
-       proc_run(PRIORITY_LOW, "include/discover_poco.php", "checkcontact");
+       Worker::add(PRIORITY_LOW, "discover_poco", "checkcontact");
 
        // Expire and remove user entries
-       proc_run(PRIORITY_MEDIUM, "include/cronjobs.php", "expire_and_remove_users");
-
-       // Check OStatus conversations
-       proc_run(PRIORITY_MEDIUM, "include/cronjobs.php", "ostatus_mentions");
-
-       // Check every conversation
-       proc_run(PRIORITY_MEDIUM, "include/cronjobs.php", "ostatus_conversations");
+       Worker::add(PRIORITY_MEDIUM, "cronjobs", "expire_and_remove_users");
 
        // Call possible post update functions
-       proc_run(PRIORITY_LOW, "include/cronjobs.php", "post_update");
+       Worker::add(PRIORITY_LOW, "cronjobs", "post_update");
 
        // update nodeinfo data
-       proc_run(PRIORITY_LOW, "include/cronjobs.php", "nodeinfo");
+       Worker::add(PRIORITY_LOW, "cronjobs", "nodeinfo");
 
        // Clear cache entries
-       proc_run(PRIORITY_LOW, "include/cronjobs.php", "clear_cache");
+       Worker::add(PRIORITY_LOW, "cronjobs", "clear_cache");
 
        // Repair missing Diaspora values in contacts
-       proc_run(PRIORITY_LOW, "include/cronjobs.php", "repair_diaspora");
+       Worker::add(PRIORITY_LOW, "cronjobs", "repair_diaspora");
 
        // Repair entries in the database
-       proc_run(PRIORITY_LOW, "include/cronjobs.php", "repair_database");
+       Worker::add(PRIORITY_LOW, "cronjobs", "repair_database");
 
        // once daily run birthday_updates and then expire in background
-       $d1 = get_config('system', 'last_expire_day');
-       $d2 = intval(datetime_convert('UTC','UTC','now','d'));
+       $d1 = Config::get('system', 'last_expire_day');
+       $d2 = intval(datetime_convert('UTC', 'UTC', 'now', 'd'));
 
        if ($d2 != intval($d1)) {
 
-               proc_run(PRIORITY_LOW, "include/cronjobs.php", "update_contact_birthdays");
+               Worker::add(PRIORITY_LOW, "cronjobs", "update_contact_birthdays");
 
-               proc_run(PRIORITY_LOW, "include/discover_poco.php", "update_server");
+               Worker::add(PRIORITY_LOW, "discover_poco", "update_server");
 
-               proc_run(PRIORITY_LOW, "include/discover_poco.php", "suggestions");
+               Worker::add(PRIORITY_LOW, "discover_poco", "suggestions");
 
-               set_config('system', 'last_expire_day', $d2);
+               Config::set('system', 'last_expire_day', $d2);
 
-               proc_run(PRIORITY_LOW, 'include/expire.php');
+               Worker::add(PRIORITY_LOW, 'expire');
 
-               proc_run(PRIORITY_MEDIUM, 'include/dbclean.php');
+               Worker::add(PRIORITY_MEDIUM, 'dbclean');
 
-               proc_run(PRIORITY_LOW, "include/cronjobs.php", "update_photo_albums");
+               Worker::add(PRIORITY_LOW, "cronjobs", "update_photo_albums");
+
+               // Delete all done workerqueue entries
+               dba::delete('workerqueue', array('`done` AND `executed` < UTC_TIMESTAMP() - INTERVAL 12 HOUR'));
+
+               // check upstream version?
+               Worker::add(PRIORITY_LOW, 'checkversion');
        }
 
        // Poll contacts
@@ -88,7 +91,7 @@ function cron_run(&$argv, &$argc){
 
        logger('cron: end');
 
-       set_config('system', 'last_cron', time());
+       Config::set('system', 'last_cron', time());
 
        return;
 }
@@ -121,6 +124,8 @@ function cron_poll_contacts($argc, $argv) {
                $force     = true;
        }
 
+       $min_poll_interval = Config::get('system', 'min_poll_interval', 1);
+
        $sql_extra = (($manual_id) ? " AND `id` = $manual_id " : "");
 
        reload_plugins();
@@ -131,7 +136,7 @@ function cron_poll_contacts($argc, $argv) {
        // and which have a polling address and ignore Diaspora since
        // we are unable to match those posts with a Diaspora GUID and prevent duplicates.
 
-       $abandon_days = intval(get_config('system', 'account_abandon_days'));
+       $abandon_days = intval(Config::get('system', 'account_abandon_days'));
        if ($abandon_days < 1) {
                $abandon_days = 0;
        }
@@ -157,7 +162,7 @@ function cron_poll_contacts($argc, $argv) {
                dbesc(NETWORK_MAIL2)
        );
 
-       if (!dbm::is_result($contacts)) {
+       if (!DBM::is_result($contacts)) {
                return;
        }
 
@@ -167,7 +172,7 @@ function cron_poll_contacts($argc, $argv) {
                        intval($c['id'])
                );
 
-               if (!dbm::is_result($res)) {
+               if (!DBM::is_result($res)) {
                        continue;
                }
 
@@ -183,18 +188,18 @@ function cron_poll_contacts($argc, $argv) {
                                $contact['priority'] = 2;
                        }
 
-                       if ($contact['subhub'] AND in_array($contact['network'], array(NETWORK_DFRN, NETWORK_ZOT, NETWORK_OSTATUS))) {
+                       if ($contact['subhub'] && in_array($contact['network'], array(NETWORK_DFRN, NETWORK_ZOT, NETWORK_OSTATUS))) {
                                /*
                                 * We should be getting everything via a hub. But just to be sure, let's check once a day.
                                 * (You can make this more or less frequent if desired by setting 'pushpoll_frequency' appropriately)
                                 * This also lets us update our subscription to the hub, and add or replace hubs in case it
                                 * changed. We will only update hubs once a day, regardless of 'pushpoll_frequency'.
                                 */
-                               $poll_interval = get_config('system', 'pushpoll_frequency');
+                               $poll_interval = Config::get('system', 'pushpoll_frequency');
                                $contact['priority'] = (($poll_interval !== false) ? intval($poll_interval) : 3);
                        }
 
-                       if ($contact['priority'] AND !$force) {
+                       if (($contact['priority'] >= 0) && !$force) {
                                $update = false;
 
                                $t = $contact['last-update'];
@@ -224,11 +229,16 @@ function cron_poll_contacts($argc, $argv) {
                                                }
                                                break;
                                        case 1:
-                                       default:
                                                if (datetime_convert('UTC', 'UTC', 'now') > datetime_convert('UTC', 'UTC', $t . " + 1 hour")) {
                                                        $update = true;
                                                }
                                                break;
+                                       case 0:
+                                       default:
+                                               if (datetime_convert('UTC', 'UTC', 'now') > datetime_convert('UTC', 'UTC', $t . " + ".$min_poll_interval." minute")) {
+                                                       $update = true;
+                                               }
+                                               break;
                                }
                                if (!$update) {
                                        continue;
@@ -237,11 +247,12 @@ function cron_poll_contacts($argc, $argv) {
 
                        logger("Polling " . $contact["network"] . " " . $contact["id"] . " " . $contact["nick"] . " " . $contact["name"]);
 
-                       if (($contact['network'] == NETWORK_FEED) AND ($contact['priority'] <= 3)) {
-                               proc_run(PRIORITY_MEDIUM, 'include/onepoll.php', intval($contact['id']));
+                       if (($contact['network'] == NETWORK_FEED) && ($contact['priority'] <= 3)) {
+                               $priority = PRIORITY_MEDIUM;
                        } else {
-                               proc_run(PRIORITY_LOW, 'include/onepoll.php', intval($contact['id']));
+                               $priority = PRIORITY_LOW;
                        }
+                       Worker::add(array('priority' => $priority, 'dont_fork' => true), 'OnePoll', (int)$contact['id']);
                }
        }
 }