diff options
author | friendica <info@friendica.com> | 2015-03-09 19:57:35 -0700 |
---|---|---|
committer | friendica <info@friendica.com> | 2015-03-09 19:57:35 -0700 |
commit | 0134a41015dd79092cb6a42ad0f7122d0af9bc6d (patch) | |
tree | 841eaab3a629984ef07fa9900303ae7c4893edae | |
parent | ef035a29bc2240ccc497d76eb6e48f2434250082 (diff) | |
download | volse-hubzilla-0134a41015dd79092cb6a42ad0f7122d0af9bc6d.tar.gz volse-hubzilla-0134a41015dd79092cb6a42ad0f7122d0af9bc6d.tar.bz2 volse-hubzilla-0134a41015dd79092cb6a42ad0f7122d0af9bc6d.zip |
more work on queue optimisations
-rw-r--r-- | include/deliver.php | 10 | ||||
-rw-r--r-- | include/notifier.php | 21 | ||||
-rw-r--r-- | include/queue.php | 15 | ||||
-rw-r--r-- | mod/admin.php | 3 | ||||
-rw-r--r-- | view/tpl/admin_queue.tpl | 4 |
5 files changed, 43 insertions, 10 deletions
diff --git a/include/deliver.php b/include/deliver.php index 498440271..0fb7a4aeb 100644 --- a/include/deliver.php +++ b/include/deliver.php @@ -20,6 +20,12 @@ function deliver_run($argv, $argc) { dbesc($argv[$x]) ); if($r) { + + /** + * Check to see if we have any recent communications with this hub (in the last month). + * If not, reduce the outq_priority. + */ + $h = parse_url($r[0]['outq_posturl']); if($h) { $base = $h['scheme'] . '://' . $h['host'] . (($h['port']) ? ':' . $h['port'] : ''); @@ -38,6 +44,8 @@ function deliver_run($argv, $argc) { } } + // "post" queue driver - used for diaspora and friendica-over-diaspora communications. + if($r[0]['outq_driver'] === 'post') { $result = z_post_url($r[0]['outq_posturl'],$r[0]['outq_msg']); if($result['success'] && $result['return_code'] < 300) { @@ -92,9 +100,11 @@ function deliver_run($argv, $argc) { logger('deliver: dest: ' . $r[0]['outq_posturl'], LOGGER_DEBUG); $result = zot_zot($r[0]['outq_posturl'],$r[0]['outq_notify']); if($result['success']) { + logger('deliver: remote zot delivery succeeded to ' . $r[0]['outq_posturl']); zot_process_response($r[0]['outq_posturl'],$result, $r[0]); } else { + logger('deliver: remote zot delivery failed to ' . $r[0]['outq_posturl']); $y = q("update outq set outq_updated = '%s' where outq_hash = '%s'", dbesc(datetime_convert()), dbesc($argv[$x]) diff --git a/include/notifier.php b/include/notifier.php index a9c4905ae..bec18142a 100644 --- a/include/notifier.php +++ b/include/notifier.php @@ -135,10 +135,25 @@ function notifier_run($argv, $argc){ )); if($data) { $result = zot_zot($hh['hubloc_callback'],$data); -// zot_queue_item is not yet written -// if(! $result['success']) -// zot_queue_item(); + // if immediate delivery failed, stick it in the queue to try again later. + + if(! $result['success']) { + $hash = random_string(); + q("insert into outq ( outq_hash, outq_account, outq_channel, outq_driver, outq_posturl, outq_async, outq_created, outq_updated, outq_notify, outq_msg ) + values ( '%s', %d, %d, '%s', '%s', %d, '%s', '%s', '%s', '%s' )", + dbesc($hash), + intval($s[0]['channel_account_id']), + intval($s[0]['channel_id']), + dbesc('zot'), + dbesc($hh['hubloc_callback']), + intval(1), + dbesc(datetime_convert()), + dbesc(datetime_convert()), + dbesc($data), + dbesc('') + ); + } } } } diff --git a/include/queue.php b/include/queue.php index 8e97b4a1a..7d2ad3b2d 100644 --- a/include/queue.php +++ b/include/queue.php @@ -46,13 +46,18 @@ function queue_run($argv, $argc){ // the site is permanently down, there's no reason to attempt delivery at all, or at most not more than once // or twice a day. - + // FIXME: can we sort postgres on outq_priority and maintain the 'distinct' ? + // The order by max(outq_priority) might be a dodgy query because of the group by. + // The desired result is to return a sequence in the order most likely to be delivered in this run. + // If a hub has already been sitting in the queue for a few days, they should be delivered last; + // hence every failure should drop them further down the priority list. + if(ACTIVE_DBTYPE == DBTYPE_POSTGRES) { $prefix = 'DISTINCT ON (outq_posturl)'; $suffix = 'ORDER BY outq_posturl'; } else { $prefix = ''; - $suffix = 'GROUP BY outq_posturl'; + $suffix = 'GROUP BY outq_posturl ORDER BY max(outq_priority)'; } $r = q("SELECT $prefix * FROM outq WHERE outq_delivered = 0 and (( outq_created > %s - INTERVAL %s and outq_updated < %s - INTERVAL %s ) OR ( outq_updated < %s - INTERVAL %s )) $suffix", db_utcnow(), db_quoteinterval('12 HOUR'), @@ -77,7 +82,7 @@ function queue_run($argv, $argc){ } else { logger('queue: queue post returned ' . $result['return_code'] . ' from ' . $rr['outq_posturl'],LOGGER_DEBUG); - $y = q("update outq set outq_updated = '%s' where outq_hash = '%s'", + $y = q("update outq set outq_updated = '%s', outq_priority = outq_priority + 10 where outq_hash = '%s'", dbesc(datetime_convert()), dbesc($rr['outq_hash']) ); @@ -86,11 +91,13 @@ function queue_run($argv, $argc){ } $result = zot_zot($rr['outq_posturl'],$rr['outq_notify']); if($result['success']) { + logger('queue: deliver zot success to ' . $rr['outq_posturl'], LOGGER_DEBUG); zot_process_response($rr['outq_posturl'],$result, $rr); } else { $deadguys[] = $rr['outq_posturl']; - $y = q("update outq set outq_updated = '%s' where outq_hash = '%s'", + logger('queue: deliver zot returned ' . $result['return_code'] . ' from ' . $rr['outq_posturl'],LOGGER_DEBUG); + $y = q("update outq set outq_updated = '%s', outq_priority = outq_priority + 10 where outq_hash = '%s'", dbesc(datetime_convert()), dbesc($rr['outq_hash']) ); diff --git a/mod/admin.php b/mod/admin.php index 8fb9866a7..daab6c9f3 100644 --- a/mod/admin.php +++ b/mod/admin.php @@ -614,7 +614,7 @@ function admin_page_queue($a) { } - $r = q("select count(outq_posturl) as total, outq_posturl from outq + $r = q("select count(outq_posturl) as total, max(outq_priority) as priority, outq_posturl from outq where outq_delivered = 0 group by outq_posturl order by total desc"); for($x = 0; $x < count($r); $x ++) { @@ -626,6 +626,7 @@ function admin_page_queue($a) { $o = replace_macros(get_markup_template('admin_queue.tpl'), array( '$banner' => t('Queue Statistics'), '$numentries' => t('Total Entries'), + '$priority' => t('Priority'), '$desturl' => t('Destination URL'), '$nukehub' => t('Mark hub permanently offline'), '$empty' => t('Empty queue for this hub'), diff --git a/view/tpl/admin_queue.tpl b/view/tpl/admin_queue.tpl index 6c2df7e31..0b59bf1c2 100644 --- a/view/tpl/admin_queue.tpl +++ b/view/tpl/admin_queue.tpl @@ -2,11 +2,11 @@ {{if $hasentries}} -<table id="admin-queue-table"><tr><td>{{$numentries}} </td><td>{{$desturl}}</td><td> </td><td> </td></tr> +<table id="admin-queue-table"><tr><td>{{$numentries}} </td><td>{{$desturl}}</td><td>{{$priority}}</td><td> </td><td> </td></tr> {{foreach $entries as $e}} -<tr><td>{{$e.total}}</td><td>{{$e.outq_posturl}}</td>{{if $expert}}<td><a href="admin/queue?f=&drophub={{$e.eurl}}" title="{{$nukehub}}" class="btn btn-default"><i class="icon-remove"></i><a></td><td><a href="admin/queue?f=&emptyhub={{$e.eurl}}" title="{{$empty}}" class="btn btn-default"><i class="icon-trash"></i></a></td>{{/if}}</tr> +<tr><td>{{$e.total}}</td><td>{{$e.outq_posturl}}</td><td>{{$e.priority}}</td>{{if $expert}}<td><a href="admin/queue?f=&drophub={{$e.eurl}}" title="{{$nukehub}}" class="btn btn-default"><i class="icon-remove"></i><a></td><td><a href="admin/queue?f=&emptyhub={{$e.eurl}}" title="{{$empty}}" class="btn btn-default"><i class="icon-trash"></i></a></td>{{/if}}</tr> {{/foreach}} </table> |