]> git.mxchange.org Git - friendica.git/blobdiff - include/cron.php
Merge pull request #3902 from annando/worker-space
[friendica.git] / include / cron.php
index 76f3e410196185514b9c24a12ef8ff3c6d8e8d62..01989826da28716ea14ddeecdd3719824e18464b 100644 (file)
@@ -1,6 +1,8 @@
 <?php
 
 use Friendica\Core\Config;
+use Friendica\Core\Worker;
+use Friendica\Database\DBM;
 
 function cron_run(&$argv, &$argc){
        global $a;
@@ -13,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;
        }
@@ -31,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');
+       $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");
+
+               Worker::add(PRIORITY_LOW, "discover_poco", "update_server");
+
+               Worker::add(PRIORITY_LOW, "discover_poco", "suggestions");
 
-               proc_run(PRIORITY_LOW, "include/discover_poco.php", "update_server");
+               Config::set('system', 'last_expire_day', $d2);
 
-               proc_run(PRIORITY_LOW, "include/discover_poco.php", "suggestions");
+               Worker::add(PRIORITY_LOW, 'expire');
 
-               set_config('system', 'last_expire_day', $d2);
+               Worker::add(PRIORITY_MEDIUM, 'dbclean');
 
-               proc_run(PRIORITY_LOW, 'include/expire.php');
+               Worker::add(PRIORITY_LOW, "cronjobs", "update_photo_albums");
 
-               proc_run(PRIORITY_MEDIUM, 'include/dbclean.php');
+               // Delete all done workerqueue entries
+               dba::delete('workerqueue', array('`done` AND `executed` < UTC_TIMESTAMP() - INTERVAL 12 HOUR'));
 
-               proc_run(PRIORITY_LOW, "include/cronjobs.php", "update_photo_albums");
+               // check upstream version?
+               Worker::add(PRIORITY_LOW, 'checkversion');
        }
 
        // Poll contacts
@@ -89,7 +91,7 @@ function cron_run(&$argv, &$argc){
 
        logger('cron: end');
 
-       set_config('system', 'last_cron', time());
+       Config::set('system', 'last_cron', time());
 
        return;
 }
@@ -134,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;
        }
@@ -160,7 +162,7 @@ function cron_poll_contacts($argc, $argv) {
                dbesc(NETWORK_MAIL2)
        );
 
-       if (!dbm::is_result($contacts)) {
+       if (!DBM::is_result($contacts)) {
                return;
        }
 
@@ -170,7 +172,7 @@ function cron_poll_contacts($argc, $argv) {
                        intval($c['id'])
                );
 
-               if (!dbm::is_result($res)) {
+               if (!DBM::is_result($res)) {
                        continue;
                }
 
@@ -193,7 +195,7 @@ function cron_poll_contacts($argc, $argv) {
                                 * 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);
                        }
 
@@ -250,7 +252,7 @@ function cron_poll_contacts($argc, $argv) {
                        } else {
                                $priority = PRIORITY_LOW;
                        }
-                       proc_run(array('priority' => $priority, 'dont_fork' => true), 'include/onepoll.php', intval($contact['id']));
+                       Worker::add(array('priority' => $priority, 'dont_fork' => true), 'OnePoll', (int)$contact['id']);
                }
        }
 }