Queue delivery should be now more reliable

This commit is contained in:
Michael Vogel 2016-01-21 03:21:33 +01:00
parent 2c410a93ff
commit 1c84054322
2 changed files with 45 additions and 26 deletions

View File

@ -52,6 +52,8 @@ function queue_run(&$argv, &$argc){
$queue_id = 0; $queue_id = 0;
$deadguys = array(); $deadguys = array();
$deadservers = array();
$serverlist = array();
logger('queue: start'); logger('queue: start');
@ -95,7 +97,7 @@ function queue_run(&$argv, &$argc){
// For the first 12 hours we'll try to deliver every 15 minutes // For the first 12 hours we'll try to deliver every 15 minutes
// 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 ))"); $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`");
} }
if(! $r){ if(! $r){
return; return;
@ -116,7 +118,7 @@ function queue_run(&$argv, &$argc){
// so check again if this entry still needs processing // so check again if this entry still needs processing
if($queue_id) { if($queue_id) {
$qi = q("select * from queue where `id` = %d limit 1", $qi = q("SELECT * FROM `queue` WHERE `id` = %d LIMIT 1",
intval($queue_id) intval($queue_id)
); );
} }
@ -142,8 +144,18 @@ function queue_run(&$argv, &$argc){
continue; continue;
} }
if (!poco_reachable($c[0]['url'])) { $server = poco_detect_server($c[0]['url']);
logger('queue: skipping probably dead url: ' . $c[0]['url']);
if (($server != "") AND !in_array($server, $serverlist)) {
logger("Check server ".$server." (".$c[0]["network"].")");
if (!poco_check_server($server, $c[0]["network"], true))
$deadservers[] = $server;
$serverlist[] = $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; continue;
} }
@ -166,37 +178,39 @@ function queue_run(&$argv, &$argc){
switch($contact['network']) { switch($contact['network']) {
case NETWORK_DFRN: case NETWORK_DFRN:
logger('queue: dfrndelivery: item ' . $q_item['id'] . ' for ' . $contact['name']); logger('queue: dfrndelivery: item '.$q_item['id'].' for '.$contact['name'].' <'.$contact['url'].'>');
$deliver_status = dfrn_deliver($owner,$contact,$data); $deliver_status = dfrn_deliver($owner,$contact,$data);
if($deliver_status == (-1)) { if($deliver_status == (-1)) {
update_queue_time($q_item['id']); update_queue_time($q_item['id']);
$deadguys[] = $contact['notify']; $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']) {
logger('queue: slapdelivery: item ' . $q_item['id'] . ' for ' . $contact['name']); logger('queue: slapdelivery: item '.$q_item['id'].' for '.$contact['name'].' <'.$contact['url'].'>');
$deliver_status = slapper($owner,$contact['notify'],$data); $deliver_status = slapper($owner,$contact['notify'],$data);
if($deliver_status == (-1)) if($deliver_status == (-1)) {
update_queue_time($q_item['id']); update_queue_time($q_item['id']);
else $deadguys[] = $contact['notify'];
} 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']) {
logger('queue: diaspora_delivery: item ' . $q_item['id'] . ' for ' . $contact['name']); logger('queue: diaspora_delivery: item '.$q_item['id'].' for '.$contact['name'].' <'.$contact['url'].'>');
$deliver_status = diaspora_transmit($owner,$contact,$data,$public,true); $deliver_status = diaspora_transmit($owner,$contact,$data,$public,true);
if($deliver_status == (-1)) if($deliver_status == (-1)) {
update_queue_time($q_item['id']); update_queue_time($q_item['id']);
else $deadguys[] = $contact['notify'];
} else
remove_queue_item($q_item['id']); remove_queue_item($q_item['id']);
} }
break; break;
@ -212,6 +226,7 @@ function queue_run(&$argv, &$argc){
break; break;
} }
logger('Deliver status '.$deliver_status.' for item '.$q_item['id'].' to '.$contact['name'].' <'.$contact['url'].'>');
} }
return; return;

View File

@ -796,19 +796,23 @@ function poco_check_server($server_url, $network = "", $force = false) {
// Test for Diaspora // Test for Diaspora
$serverret = z_fetch_url($server_url); $serverret = z_fetch_url($server_url);
$lines = explode("\n",$serverret["header"]); if (!$serverret["success"] OR ($serverret["body"] == ""))
if(count($lines)) $failure = true;
foreach($lines as $line) { else {
$line = trim($line); $lines = explode("\n",$serverret["header"]);
if(stristr($line,'X-Diaspora-Version:')) { if(count($lines))
$platform = "Diaspora"; foreach($lines as $line) {
$version = trim(str_replace("X-Diaspora-Version:", "", $line)); $line = trim($line);
$version = trim(str_replace("x-diaspora-version:", "", $version)); if(stristr($line,'X-Diaspora-Version:')) {
$network = NETWORK_DIASPORA; $platform = "Diaspora";
$versionparts = explode("-", $version); $version = trim(str_replace("X-Diaspora-Version:", "", $line));
$version = $versionparts[0]; $version = trim(str_replace("x-diaspora-version:", "", $version));
$network = NETWORK_DIASPORA;
$versionparts = explode("-", $version);
$version = $versionparts[0];
}
} }
} }
} }
if (!$failure) { if (!$failure) {