3 use \Friendica\Core\Config;
5 require_once('include/queue_fn.php');
6 require_once('include/dfrn.php');
7 require_once("include/datetime.php");
8 require_once('include/items.php');
9 require_once('include/bbcode.php');
10 require_once('include/socgraph.php');
11 require_once('include/cache.php');
13 function queue_run(&$argv, &$argc){
17 $queue_id = intval($argv[1]);
22 $cachekey_deadguy = 'queue_run:deadguy:';
23 $cachekey_server = 'queue_run:server:';
27 logger('queue: start');
29 // Handling the pubsubhubbub requests
30 proc_run(PRIORITY_HIGH,'include/pubsubpublish.php');
32 $r = q("SELECT `queue`.*, `contact`.`name`, `contact`.`uid` FROM `queue`
33 INNER JOIN `contact` ON `queue`.`cid` = `contact`.`id`
34 WHERE `queue`.`created` < UTC_TIMESTAMP() - INTERVAL 3 DAY");
37 logger('Removing expired queue item for ' . $rr['name'] . ', uid=' . $rr['uid']);
38 logger('Expired queue data: ' . $rr['content'], LOGGER_DATA);
40 q("DELETE FROM `queue` WHERE `created` < UTC_TIMESTAMP() - INTERVAL 3 DAY");
43 // For the first 12 hours we'll try to deliver every 15 minutes
44 // After that, we'll only attempt delivery once per hour.
46 $r = q("SELECT `id` FROM `queue` WHERE ((`created` > UTC_TIMESTAMP() - INTERVAL 12 HOUR && `last` < UTC_TIMESTAMP() - INTERVAL 15 MINUTE) OR (`last` < UTC_TIMESTAMP() - INTERVAL 1 HOUR)) ORDER BY `cid`, `created`");
48 call_hooks('queue_predeliver', $a, $r);
50 if (dbm::is_result($r)) {
51 foreach ($r as $q_item) {
52 logger('Call queue for id '.$q_item['id']);
53 proc_run(PRIORITY_LOW, "include/queue.php", $q_item['id']);
62 require_once('include/salmon.php');
63 require_once('include/diaspora.php');
65 $r = q("SELECT * FROM `queue` WHERE `id` = %d LIMIT 1",
68 if (!dbm::is_result($r)) {
74 $c = q("SELECT * FROM `contact` WHERE `id` = %d LIMIT 1",
75 intval($q_item['cid'])
78 if (!dbm::is_result($c)) {
79 remove_queue_item($q_item['id']);
83 $dead = Cache::get($cachekey_deadguy.$c[0]['notify']);
85 if (!is_null($dead) AND $dead) {
86 logger('queue: skipping known dead url: '.$c[0]['notify']);
87 update_queue_time($q_item['id']);
91 $server = poco_detect_server($c[0]['url']);
94 $vital = Cache::get($cachekey_server.$server);
96 if (is_null($vital)) {
97 logger("Check server ".$server." (".$c[0]["network"].")");
99 $vital = poco_check_server($server, $c[0]["network"], true);
100 Cache::set($cachekey_server.$server, $vital, CACHE_QUARTER_HOUR);
103 if (!is_null($vital) AND !$vital) {
104 logger('queue: skipping dead server: '.$server);
105 update_queue_time($q_item['id']);
110 $u = q("SELECT `user`.*, `user`.`pubkey` AS `upubkey`, `user`.`prvkey` AS `uprvkey`
111 FROM `user` WHERE `uid` = %d LIMIT 1",
114 if (!dbm::is_result($u)) {
115 remove_queue_item($q_item['id']);
119 $data = $q_item['content'];
120 $public = $q_item['batch'];
126 switch ($contact['network']) {
128 logger('queue: dfrndelivery: item '.$q_item['id'].' for '.$contact['name'].' <'.$contact['url'].'>');
129 $deliver_status = dfrn::deliver($owner, $contact, $data);
131 if ($deliver_status == (-1)) {
132 update_queue_time($q_item['id']);
133 Cache::set($cachekey_deadguy.$contact['notify'], true, CACHE_QUARTER_HOUR);
135 remove_queue_item($q_item['id']);
138 case NETWORK_OSTATUS:
139 if ($contact['notify']) {
140 logger('queue: slapdelivery: item '.$q_item['id'].' for '.$contact['name'].' <'.$contact['url'].'>');
141 $deliver_status = slapper($owner, $contact['notify'], $data);
143 if ($deliver_status == (-1)) {
144 update_queue_time($q_item['id']);
145 Cache::set($cachekey_deadguy.$contact['notify'], true, CACHE_QUARTER_HOUR);
147 remove_queue_item($q_item['id']);
151 case NETWORK_DIASPORA:
152 if ($contact['notify']) {
153 logger('queue: diaspora_delivery: item '.$q_item['id'].' for '.$contact['name'].' <'.$contact['url'].'>');
154 $deliver_status = Diaspora::transmit($owner, $contact, $data, $public, true);
156 if ($deliver_status == (-1)) {
157 update_queue_time($q_item['id']);
158 Cache::set($cachekey_deadguy.$contact['notify'], true, CACHE_QUARTER_HOUR);
160 remove_queue_item($q_item['id']);
166 $params = array('owner' => $owner, 'contact' => $contact, 'queue' => $q_item, 'result' => false);
167 call_hooks('queue_deliver', $a, $params);
169 if ($params['result']) {
170 remove_queue_item($q_item['id']);
172 update_queue_time($q_item['id']);
177 logger('Deliver status '.(int)$deliver_status.' for item '.$q_item['id'].' to '.$contact['name'].' <'.$contact['url'].'>');