Queue.php is now reworked
This commit is contained in:
parent
df6913f7e1
commit
3c220dd40c
|
@ -1,7 +1,5 @@
|
|||
<?php
|
||||
|
||||
/// @todo Rework the whole file to a single item processing
|
||||
|
||||
use \Friendica\Core\Config;
|
||||
|
||||
require_once('include/queue_fn.php');
|
||||
|
@ -19,10 +17,6 @@ function queue_run(&$argv, &$argc){
|
|||
else
|
||||
$queue_id = 0;
|
||||
|
||||
$deadguys = array();
|
||||
$deadservers = array();
|
||||
$serverlist = array();
|
||||
|
||||
if (!$queue_id) {
|
||||
|
||||
logger('queue: start');
|
||||
|
@ -53,72 +47,52 @@ function queue_run(&$argv, &$argc){
|
|||
// 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`");
|
||||
} else {
|
||||
logger('queue: start for id '.$queue_id);
|
||||
|
||||
$r = q("SELECT `id` FROM `queue` WHERE `id` = %d LIMIT 1",
|
||||
intval($queue_id)
|
||||
);
|
||||
call_hooks('queue_predeliver', $a, $r);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
if (!$queue_id)
|
||||
call_hooks('queue_predeliver', $a, $r);
|
||||
|
||||
|
||||
// delivery loop
|
||||
// delivering
|
||||
|
||||
require_once('include/salmon.php');
|
||||
require_once('include/diaspora.php');
|
||||
|
||||
foreach($r as $q_item) {
|
||||
|
||||
// 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",
|
||||
$r = q("SELECT * FROM `queue` WHERE `id` = %d LIMIT 1",
|
||||
intval($queue_id));
|
||||
} else {
|
||||
logger('Call queue for id '.$q_item['id']);
|
||||
proc_run(PRIORITY_LOW, "include/queue.php", $q_item['id']);
|
||||
continue;
|
||||
|
||||
if (!dbm::is_result($r)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(! count($qi))
|
||||
continue;
|
||||
|
||||
$q_item = $r[0];
|
||||
|
||||
$c = q("SELECT * FROM `contact` WHERE `id` = %d LIMIT 1",
|
||||
intval($qi[0]['cid'])
|
||||
intval($q_item['cid'])
|
||||
);
|
||||
|
||||
if (!dbm::is_result($c)) {
|
||||
remove_queue_item($q_item['id']);
|
||||
continue;
|
||||
}
|
||||
if(in_array($c[0]['notify'],$deadguys)) {
|
||||
logger('queue: skipping known dead url: ' . $c[0]['notify']);
|
||||
update_queue_time($q_item['id']);
|
||||
continue;
|
||||
return;
|
||||
}
|
||||
|
||||
$server = poco_detect_server($c[0]['url']);
|
||||
|
||||
if (($server != "") AND !in_array($server, $serverlist)) {
|
||||
if ($server != "") {
|
||||
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);
|
||||
if (!poco_check_server($server, $c[0]["network"], true)) {
|
||||
logger('queue: skipping dead server: '.$server);
|
||||
update_queue_time($q_item['id']);
|
||||
continue;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$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)) {
|
||||
remove_queue_item($q_item['id']);
|
||||
continue;
|
||||
return;
|
||||
}
|
||||
|
||||
$data = $qi[0]['content'];
|
||||
$public = $qi[0]['batch'];
|
||||
$data = $q_item['content'];
|
||||
$public = $q_item['batch'];
|
||||
$contact = $c[0];
|
||||
$owner = $u[0];
|
||||
|
||||
|
@ -144,10 +118,9 @@ function queue_run(&$argv, &$argc){
|
|||
|
||||
if ($deliver_status == (-1)) {
|
||||
update_queue_time($q_item['id']);
|
||||
$deadguys[] = $contact['notify'];
|
||||
} else
|
||||
} else {
|
||||
remove_queue_item($q_item['id']);
|
||||
|
||||
}
|
||||
break;
|
||||
case NETWORK_OSTATUS:
|
||||
if ($contact['notify']) {
|
||||
|
@ -156,10 +129,10 @@ function queue_run(&$argv, &$argc){
|
|||
|
||||
if ($deliver_status == (-1)) {
|
||||
update_queue_time($q_item['id']);
|
||||
$deadguys[] = $contact['notify'];
|
||||
} else
|
||||
} else {
|
||||
remove_queue_item($q_item['id']);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case NETWORK_DIASPORA:
|
||||
if ($contact['notify']) {
|
||||
|
@ -168,10 +141,9 @@ function queue_run(&$argv, &$argc){
|
|||
|
||||
if ($deliver_status == (-1)) {
|
||||
update_queue_time($q_item['id']);
|
||||
$deadguys[] = $contact['notify'];
|
||||
} else
|
||||
} else {
|
||||
remove_queue_item($q_item['id']);
|
||||
|
||||
}
|
||||
}
|
||||
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'].'>');
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user