Queue.php is now reworked

This commit is contained in:
Michael 2017-02-27 21:07:32 +00:00
parent df6913f7e1
commit 3c220dd40c

View File

@ -1,7 +1,5 @@
<?php <?php
/// @todo Rework the whole file to a single item processing
use \Friendica\Core\Config; use \Friendica\Core\Config;
require_once('include/queue_fn.php'); require_once('include/queue_fn.php');
@ -19,10 +17,6 @@ function queue_run(&$argv, &$argc){
else else
$queue_id = 0; $queue_id = 0;
$deadguys = array();
$deadservers = array();
$serverlist = array();
if (!$queue_id) { if (!$queue_id) {
logger('queue: start'); logger('queue: start');
@ -53,72 +47,52 @@ function queue_run(&$argv, &$argc){
// After that, we'll only attempt delivery once per hour. // After that, we'll only attempt delivery once per hour.
$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`"); $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`");
} else {
logger('queue: start for id '.$queue_id);
$r = q("SELECT `id` FROM `queue` WHERE `id` = %d LIMIT 1", call_hooks('queue_predeliver', $a, $r);
intval($queue_id)
); if (dbm::is_result) {
foreach ($r as $q_item) {
logger('Call queue for id '.$q_item['id']);
proc_run(PRIORITY_LOW, "include/queue.php", $q_item['id']);
}
} }
if (!$r){
return; return;
} }
if (!$queue_id)
call_hooks('queue_predeliver', $a, $r);
// delivering
// delivery loop
require_once('include/salmon.php'); require_once('include/salmon.php');
require_once('include/diaspora.php'); require_once('include/diaspora.php');
foreach($r as $q_item) { $r = q("SELECT * FROM `queue` WHERE `id` = %d LIMIT 1",
// queue_predeliver hooks may have changed the queue db details,
// so check again if this entry still needs processing
if ($queue_id) {
$qi = q("SELECT * FROM `queue` WHERE `id` = %d LIMIT 1",
intval($queue_id)); intval($queue_id));
} else {
logger('Call queue for id '.$q_item['id']); if (!dbm::is_result($r)) {
proc_run(PRIORITY_LOW, "include/queue.php", $q_item['id']); return;
continue;
} }
if(! count($qi)) $q_item = $r[0];
continue;
$c = q("SELECT * FROM `contact` WHERE `id` = %d LIMIT 1", $c = q("SELECT * FROM `contact` WHERE `id` = %d LIMIT 1",
intval($qi[0]['cid']) intval($q_item['cid'])
); );
if (!dbm::is_result($c)) { if (!dbm::is_result($c)) {
remove_queue_item($q_item['id']); remove_queue_item($q_item['id']);
continue; return;
}
if(in_array($c[0]['notify'],$deadguys)) {
logger('queue: skipping known dead url: ' . $c[0]['notify']);
update_queue_time($q_item['id']);
continue;
} }
$server = poco_detect_server($c[0]['url']); $server = poco_detect_server($c[0]['url']);
if (($server != "") AND !in_array($server, $serverlist)) { if ($server != "") {
logger("Check server ".$server." (".$c[0]["network"].")"); logger("Check server ".$server." (".$c[0]["network"].")");
if (!poco_check_server($server, $c[0]["network"], true))
$deadservers[] = $server;
$serverlist[] = $server; if (!poco_check_server($server, $c[0]["network"], true)) {
} logger('queue: skipping dead server: '.$server);
if (($server != "") AND in_array($server, $deadservers)) {
logger('queue: skipping known dead server: '.$server);
update_queue_time($q_item['id']); update_queue_time($q_item['id']);
continue; return;
}
} }
$u = q("SELECT `user`.*, `user`.`pubkey` AS `upubkey`, `user`.`prvkey` AS `uprvkey` $u = q("SELECT `user`.*, `user`.`pubkey` AS `upubkey`, `user`.`prvkey` AS `uprvkey`
@ -127,11 +101,11 @@ function queue_run(&$argv, &$argc){
); );
if (!dbm::is_result($u)) { if (!dbm::is_result($u)) {
remove_queue_item($q_item['id']); remove_queue_item($q_item['id']);
continue; return;
} }
$data = $qi[0]['content']; $data = $q_item['content'];
$public = $qi[0]['batch']; $public = $q_item['batch'];
$contact = $c[0]; $contact = $c[0];
$owner = $u[0]; $owner = $u[0];
@ -144,10 +118,9 @@ function queue_run(&$argv, &$argc){
if ($deliver_status == (-1)) { if ($deliver_status == (-1)) {
update_queue_time($q_item['id']); update_queue_time($q_item['id']);
$deadguys[] = $contact['notify']; } else {
} else
remove_queue_item($q_item['id']); remove_queue_item($q_item['id']);
}
break; break;
case NETWORK_OSTATUS: case NETWORK_OSTATUS:
if ($contact['notify']) { if ($contact['notify']) {
@ -156,10 +129,10 @@ function queue_run(&$argv, &$argc){
if ($deliver_status == (-1)) { if ($deliver_status == (-1)) {
update_queue_time($q_item['id']); update_queue_time($q_item['id']);
$deadguys[] = $contact['notify']; } else {
} else
remove_queue_item($q_item['id']); remove_queue_item($q_item['id']);
} }
}
break; break;
case NETWORK_DIASPORA: case NETWORK_DIASPORA:
if ($contact['notify']) { if ($contact['notify']) {
@ -168,10 +141,9 @@ function queue_run(&$argv, &$argc){
if ($deliver_status == (-1)) { if ($deliver_status == (-1)) {
update_queue_time($q_item['id']); update_queue_time($q_item['id']);
$deadguys[] = $contact['notify']; } else {
} else
remove_queue_item($q_item['id']); remove_queue_item($q_item['id']);
}
} }
break; break;
@ -188,7 +160,6 @@ function queue_run(&$argv, &$argc){
} }
logger('Deliver status '.$deliver_status.' for item '.$q_item['id'].' to '.$contact['name'].' <'.$contact['url'].'>'); logger('Deliver status '.$deliver_status.' for item '.$q_item['id'].' to '.$contact['name'].' <'.$contact['url'].'>');
}
return; return;
} }