X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=lib%2Fqueuehandler.php;h=23f295c45296fb480e233e4add9e7bb3fcc15782;hb=2abe10b8ea4b5d69fc7f6513bf465541454ca2cf;hp=747e7b49303dd8bd5267615a9dcf48b334342c08;hpb=9cdb33ac0e79ce386dc7ab822755c5ef7080f3be;p=quix0rs-gnu-social.git diff --git a/lib/queuehandler.php b/lib/queuehandler.php index 747e7b4930..23f295c452 100644 --- a/lib/queuehandler.php +++ b/lib/queuehandler.php @@ -19,7 +19,13 @@ define('CLAIM_TIMEOUT', 1200); -class QueueHandler { +if (!defined('LACONICA')) { exit(1); } + +require_once(INSTALLDIR.'/lib/daemon.php'); +require_once(INSTALLDIR.'/classes/Queue_item.php'); +require_once(INSTALLDIR.'/classes/Notice.php'); + +class QueueHandler extends Daemon { var $_id = 'generic'; @@ -32,6 +38,10 @@ class QueueHandler { function class_name() { return ucfirst($this->transport()) . 'Handler'; } + + function name() { + return strtolower($this->class_name().'.'.$this->get_id()); + } function get_id() { return $this->_id; @@ -55,9 +65,11 @@ class QueueHandler { return true; } - function handle_queue() { + function run() { + if (!$this->start()) { + return false; + } $this->log(LOG_INFO, 'checking for queued notices'); - $cnt = 0; $transport = $this->transport(); do { $qi = Queue_item::top($transport); @@ -77,24 +89,40 @@ class QueueHandler { continue; } $this->log(LOG_INFO, 'finished broadcasting notice ID = ' . $notice->id); + $notice->free(); + unset($notice); $notice = NULL; } else { $this->log(LOG_WARNING, 'queue item for notice that does not exist'); } $qi->delete(); - $cnt++; + $qi->free(); + unset($qi); + $this->idle(0); } else { $this->clear_old_claims(); - sleep(10); + $this->idle(5); } } while (true); + if (!$this->finish()) { + return false; + } + return true; } + function idle($timeout=0) { + if ($timeout>0) { + sleep($timeout); + } + } + function clear_old_claims() { $qi = new Queue_item(); $qi->transport = $this->transport(); $qi->whereAdd('now() - claimed > '.CLAIM_TIMEOUT); $qi->update(DB_DATAOBJECT_WHEREADD_ONLY); + $qi->free(); + unset($qi); } function log($level, $msg) {