delivery optimisations

This commit is contained in:
redmatrix 2015-09-24 22:51:47 -07:00
parent e558ddae3f
commit 98f656cfcb
2 changed files with 54 additions and 8 deletions

29
include/deliver_hooks.php Normal file
View File

@ -0,0 +1,29 @@
<?php
require_once('include/cli_startup.php');
require_once('include/zot.php');
function deliver_hooks_run($argv, $argc) {
cli_startup();
$a = get_app();
if($argc < 2)
return;
$r = q("select * from item where id = '%d'",
intval($argv[1])
);
if($r)
call_hooks('notifier_normal',$r[0]);
}
if (array_search(__file__,get_included_files())===0){
deliver_hooks_run($argv,$argc);
killme();
}

View File

@ -579,7 +579,7 @@ function notifier_run($argv, $argc){
if($deliveries_per_process <= 0) if($deliveries_per_process <= 0)
$deliveries_per_process = 1; $deliveries_per_process = 1;
$deliver = array(); $deliveries = array();
foreach($dhubs as $hub) { foreach($dhubs as $hub) {
@ -675,7 +675,7 @@ function notifier_run($argv, $argc){
); );
} }
} }
$deliver[] = $hash; $deliveries[] = $hash;
if(count($deliver) >= $deliveries_per_process) { if(count($deliver) >= $deliveries_per_process) {
proc_run('php','include/deliver.php',$deliver); proc_run('php','include/deliver.php',$deliver);
@ -684,18 +684,35 @@ function notifier_run($argv, $argc){
@time_sleep_until(microtime(true) + (float) $interval); @time_sleep_until(microtime(true) + (float) $interval);
} }
} }
if($normal_mode) {
$x = q("select * from hook where hook = 'notifier_normal'");
if($x)
proc_run('php','deliver_hooks.php', $target_item['id']);
}
if($deliveries) {
$deliver = array();
foreach($deliveries as $d) {
$deliver[] = $d;
if(count($deliver) >= $deliveries_per_process) {
proc_run('php','include/deliver.php',$deliver);
$deliver = array();
if($interval)
@time_sleep_until(microtime(true) + (float) $interval);
}
}
}
// catch any stragglers // catch any stragglers
if(count($deliver)) { if($deliver)
proc_run('php','include/deliver.php',$deliver); proc_run('php','include/deliver.php',$deliver);
}
logger('notifier: basic loop complete.', LOGGER_DEBUG); logger('notifier: basic loop complete.', LOGGER_DEBUG);
if($normal_mode)
call_hooks('notifier_normal',$target_item);
call_hooks('notifier_end',$target_item); call_hooks('notifier_end',$target_item);