]> git.mxchange.org Git - friendica.git/blob - src/Worker/Cron.php
Changed priority
[friendica.git] / src / Worker / Cron.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2020, Friendica
4  *
5  * @license GNU AGPL version 3 or any later version
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU Affero General Public License as
9  * published by the Free Software Foundation, either version 3 of the
10  * License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU Affero General Public License for more details.
16  *
17  * You should have received a copy of the GNU Affero General Public License
18  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
19  *
20  */
21
22 namespace Friendica\Worker;
23
24 use Friendica\Core\Hook;
25 use Friendica\Core\Logger;
26 use Friendica\Core\Worker;
27 use Friendica\DI;
28
29 class Cron
30 {
31         public static function execute()
32         {
33                 $a = DI::app();
34
35                 $last = DI::config()->get('system', 'last_cron');
36
37                 $poll_interval = intval(DI::config()->get('system', 'cron_interval'));
38
39                 if ($last) {
40                         $next = $last + ($poll_interval * 60);
41                         if ($next > time()) {
42                                 Logger::notice('cron intervall not reached');
43                                 return;
44                         }
45                 }
46
47                 Logger::notice('start');
48
49                 // Ensure to have a .htaccess file.
50                 // this is a precaution for systems that update automatically
51                 $basepath = $a->getBasePath();
52                 if (!file_exists($basepath . '/.htaccess') && is_writable($basepath)) {
53                         copy($basepath . '/.htaccess-dist', $basepath . '/.htaccess');
54                 }
55
56                 // Fork the cron jobs in separate parts to avoid problems when one of them is crashing
57                 Hook::fork($a->queue['priority'], 'cron');
58
59                 // Poll contacts
60                 Worker::add(PRIORITY_MEDIUM, 'PollContacts');
61
62                 // Update contact information
63                 Worker::add(PRIORITY_LOW, 'UpdatePublicContacts');              
64
65                 // run the process to update server directories in the background
66                 Worker::add(PRIORITY_LOW, 'UpdateServerDirectories');
67
68                 // Expire and remove user entries
69                 Worker::add(PRIORITY_MEDIUM, 'ExpireAndRemoveUsers');
70
71                 // Call possible post update functions
72                 Worker::add(PRIORITY_LOW, 'PostUpdate');
73
74                 // Repair entries in the database
75                 Worker::add(PRIORITY_LOW, 'RepairDatabase');
76
77                 // Hourly cron calls
78                 if (DI::config()->get('system', 'last_cron_hourly', 0) + 3600 < time()) {
79
80                         // Search for new contacts in the directory
81                         if (DI::config()->get('system', 'synchronize_directory')) {
82                                 Worker::add(PRIORITY_LOW, 'PullDirectory');
83                         }
84
85                         // Delete all done workerqueue entries                  
86                         Worker::add(PRIORITY_LOW, 'ClearWorkerqueue');
87
88                         // Clear cache entries
89                         Worker::add(PRIORITY_LOW, 'ClearCache');
90
91                         DI::config()->set('system', 'last_cron_hourly', time());
92                 }
93
94                 // Daily cron calls
95                 if (DI::config()->get('system', 'last_cron_daily', 0) + 86400 < time()) {
96
97                         Worker::add(PRIORITY_LOW, 'UpdateContactBirthdays');
98
99                         Worker::add(PRIORITY_LOW, 'UpdatePhotoAlbums');
100
101                         // update nodeinfo data
102                         Worker::add(PRIORITY_LOW, 'NodeInfo');
103
104                         Worker::add(PRIORITY_LOW, 'UpdateGServers');
105
106                         Worker::add(PRIORITY_LOW, 'Expire');
107
108                         Worker::add(PRIORITY_MEDIUM, 'DBClean');
109
110                         Worker::add(PRIORITY_LOW, 'ExpireConversations');
111
112                         Worker::add(PRIORITY_LOW, 'CleanItemUri');
113
114                         // check upstream version?
115                         Worker::add(PRIORITY_LOW, 'CheckVersion');
116
117                         Worker::add(PRIORITY_LOW, 'CheckdeletedContacts');
118
119                         if (DI::config()->get('system', 'optimize_tables')) {
120                                 Worker::add(PRIORITY_LOW, 'OptimizeTables');
121                         }
122         
123                         DI::config()->set('system', 'last_cron_daily', time());
124                 }
125
126                 Logger::notice('end');
127
128                 DI::config()->set('system', 'last_cron', time());
129         }
130 }