streams/include/queue.php

84 lines
2.5 KiB
PHP
Raw Normal View History

2013-02-26 01:09:40 +00:00
<?php /** @file */
require_once("boot.php");
2012-10-23 10:26:12 +00:00
require_once('include/cli_startup.php');
require_once('include/queue_fn.php');
2013-01-06 12:07:10 +00:00
require_once('include/zot.php');
2010-11-22 22:53:25 +00:00
function queue_run($argv, $argc){
2010-11-22 22:53:25 +00:00
2012-10-23 10:26:12 +00:00
cli_startup();
2012-12-31 05:44:59 +00:00
2012-10-23 10:26:12 +00:00
global $a;
2010-11-22 22:53:25 +00:00
require_once('include/items.php');
require_once('include/bbcode.php');
2012-10-23 10:26:12 +00:00
if(argc() > 1)
2012-12-31 05:44:59 +00:00
$queue_id = argv(1);
else
$queue_id = 0;
$deadguys = array();
2010-11-26 02:31:33 +00:00
logger('queue: start');
2010-11-22 22:53:25 +00:00
2012-12-31 05:44:59 +00:00
$r = q("DELETE FROM outq WHERE outq_created < UTC_TIMESTAMP() - INTERVAL 3 DAY");
2012-12-19 00:29:57 +00:00
if($queue_id) {
2012-12-31 05:44:59 +00:00
$r = q("SELECT * FROM outq WHERE outq_hash = '%s' LIMIT 1",
dbesc($queue_id)
);
}
else {
2010-11-22 22:53:25 +00:00
// For the first 12 hours we'll try to deliver every 15 minutes
// After that, we'll only attempt delivery once per hour.
// This currently only handles the default queue drivers ('zot' or '') which we will group by posturl
// so that we don't start off a thousand deliveries for a couple of dead hubs.
// The zot driver will deliver everything destined for a single hub once contact is made (*if* contact is made).
// Other drivers will have to do something different here and may need their own query.
$r = q("SELECT * FROM outq WHERE outq_delivered = 0 and (( outq_created > UTC_TIMESTAMP() - INTERVAL 12 HOUR and outq_updated < UTC_TIMESTAMP() - INTERVAL 15 MINUTE ) OR ( outq_updated < UTC_TIMESTAMP() - INTERVAL 1 HOUR )) and outq_driver in ('','zot') group by outq_posturl");
}
2012-12-31 05:44:59 +00:00
if(! $r)
return;
2011-06-05 09:18:18 +00:00
2012-12-31 05:44:59 +00:00
foreach($r as $rr) {
2013-03-12 00:42:12 +00:00
if(in_array($rr['outq_posturl'],$deadguys))
2012-12-31 05:44:59 +00:00
continue;
2014-08-29 04:49:13 +00:00
if($rr['outq_driver'] === 'post') {
$result = z_post_url($rr['outq_posturl'],$rr['outq_msg']);
if($result['success'] && $result['return_code'] < 300) {
logger('deliver: queue post success to ' . $rr['outq_posturl'], LOGGER_DEBUG);
$y = q("update outq set outq_delivered = '%s' where outq_hash = '%s' limit 1",
dbesc($rr['ouq_hash'])
);
}
else {
$y = q("update outq set outq_updated = '%s' where outq_hash = '%s' limit 1",
dbesc(datetime_convert()),
dbesc($rr['outq_hash'])
);
}
continue;
}
2012-12-31 05:44:59 +00:00
$result = zot_zot($rr['outq_posturl'],$rr['outq_notify']);
if($result['success']) {
2012-12-31 22:45:26 +00:00
zot_process_response($rr['outq_posturl'],$result, $rr);
}
else {
2013-03-12 00:42:12 +00:00
$deadguys[] = $rr['outq_posturl'];
2012-12-31 05:44:59 +00:00
$y = q("update outq set outq_updated = '%s' where outq_hash = '%s' limit 1",
dbesc(datetime_convert()),
dbesc($rr['outq_hash'])
);
}
2010-11-22 22:53:25 +00:00
}
}
2010-11-22 22:53:25 +00:00
if (array_search(__file__,get_included_files())===0){
queue_run($argv,$argc);
killme();
}