From 846c4cea7c0e3868a63a187ee9a504a031b2a7e4 Mon Sep 17 00:00:00 2001 From: Friendika Date: Sun, 28 Aug 2011 21:41:42 -0700 Subject: implement delivery queue in case notifier gets killed --- include/notifier.php | 45 ++++++++++++++++++++++++++++++++------------- 1 file changed, 32 insertions(+), 13 deletions(-) (limited to 'include/notifier.php') diff --git a/include/notifier.php b/include/notifier.php index b87aa95b1..cde156cbd 100644 --- a/include/notifier.php +++ b/include/notifier.php @@ -379,11 +379,27 @@ function notifier_run($argv, $argc){ dbesc($recip_str) ); - // delivery loop require_once('include/salmon.php'); + $interval = intval(get_config('system','delivery_interval')); + if(! $interval) + $interval = 2; + + // delivery loop + if(count($r)) { + + foreach($r as $contact) { + if((! $mail) && (! $fsuggest) && (! $followup) && (! $contact['self'])) { + q("insert into deliverq ( `cmd`,`item`,`contact` ) values ('%s', %d, %d )", + dbesc($cmd), + intval($item_id), + intval($contact['id']) + ); + } + } + foreach($r as $contact) { if($contact['self']) continue; @@ -392,13 +408,8 @@ function notifier_run($argv, $argc){ // we will deliver single recipient types of message and email receipients here. if((! $mail) && (! $fsuggest) && (! $followup)) { - $interval = intval(get_config('system','delivery_interval')); - if(! $interval) - $interval = 2; - proc_run('php','include/delivery.php',$cmd,$item_id,$contact['id']); - sleep($interval); - continue; + @time_sleep_until(microtime(true) + (float) $interval); } $deliver_status = 0; @@ -624,6 +635,18 @@ function notifier_run($argv, $argc){ if(count($r)) { logger('pubdeliver: ' . print_r($r,true)); + // throw everything into the queue in case we get killed + + foreach($r as $rr) { + if((! $mail) && (! $fsuggest) && (! $followup)) { + q("insert into deliverq ( `cmd`,`item`,`contact` ) values ('%s', %d, %d )", + dbesc($cmd), + intval($item_id), + intval($rr['id']) + ); + } + } + foreach($r as $rr) { /* Don't deliver to folks who have already been delivered to */ @@ -634,13 +657,9 @@ function notifier_run($argv, $argc){ } if((! $mail) && (! $fsuggest) && (! $followup)) { - $interval = intval(get_config('system','delivery_interval')); - if(! $interval) - $interval = 2; - + logger('notifier: delivery agent: ' . $rr['name'] . ' ' . $rr['id']); proc_run('php','include/delivery.php',$cmd,$item_id,$rr['id']); - sleep($interval); - continue; + @time_sleep_until(microtime(true) + (float) $interval); } } } -- cgit v1.2.3