X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2Fqueue.php;h=fb65d5c25bcbaf88e91815a98c2f9a11259a0473;hb=d28d2ff440efba47ad65cf28eab4be96e0ea05b2;hp=7df510ef43226d27ca3bf0b03915212846a1d4a7;hpb=fb58801aa406d1dd250d614b02f63f0b72bae6b6;p=friendica.git diff --git a/include/queue.php b/include/queue.php index 7df510ef43..fb65d5c25b 100644 --- a/include/queue.php +++ b/include/queue.php @@ -1,29 +1,20 @@ set_baseurl(get_config('system','url')); + load_hooks(); + + $deadguys = array(); + + logger('queue: start'); $r = q("SELECT `queue`.*, `contact`.`name`, `contact`.`uid` FROM `queue` LEFT JOIN `contact` ON `queue`.`cid` = `contact`.`id` @@ -47,27 +46,42 @@ function remove_queue_item($id) { $r = q("SELECT `id` FROM `queue` WHERE `last` < UTC_TIMESTAMP() - INTERVAL 15 MINUTE "); - if(! count($r)) - killme(); + if(! count($r)){ + return; + } + + call_hooks('queue_predeliver', $a, $r); + // delivery loop require_once('include/salmon.php'); foreach($r as $q_item) { - $qi = 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 + + $qi = q("SELECT * FROM `queue` WHERE `id` = %d AND `last` < UTC_TIMESTAMP() - INTERVAL 15 MINUTE ", intval($q_item['id']) ); if(! count($qi)) continue; + $c = q("SELECT * FROM `contact` WHERE `id` = %d LIMIT 1", - intval($q_item['cid']) + intval($qi[0]['cid']) ); if(! count($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; + } + $u = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1", intval($c[0]['uid']) ); @@ -83,17 +97,19 @@ function remove_queue_item($id) { $deliver_status = 0; switch($contact['network']) { - case 'dfrn': + case NETWORK_DFRN: logger('queue: dfrndelivery: item ' . $q_item['id'] . ' for ' . $contact['name']); $deliver_status = dfrn_deliver($owner,$contact,$data); - if($deliver_status == (-1)) + if($deliver_status == (-1)) { update_queue_time($q_item['id']); - else + $deadguys[] = $contact['notify']; + } + else { remove_queue_item($q_item['id']); - + } break; - default: + case NETWORK_OSTATUS: if($contact['notify']) { logger('queue: slapdelivery: item ' . $q_item['id'] . ' for ' . $contact['name']); $deliver_status = slapper($owner,$contact['notify'],$data); @@ -104,10 +120,25 @@ function remove_queue_item($id) { remove_queue_item($q_item['id']); } break; + default: + $params = array('owner' => $owner, 'contact' => $contact, 'queue' => $q_item, 'result' => false); + call_hooks('queue_deliver', $a, $params); + + if($params['result']) + remove_queue_item($q_item['id']); + else + update_queue_time($q_item['id']); + + break; + } } - killme(); + return; - // NOTREACHED +} +if (array_search(__file__,get_included_files())===0){ + queue_run($argv,$argc); + killme(); +}