]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - lib/queuehandler.php
allow doc and api calls from private
[quix0rs-gnu-social.git] / lib / queuehandler.php
index a1214986a8fa9a5ea3672511a1ce15cf12ddb767..23f295c45296fb480e233e4add9e7bb3fcc15782 100644 (file)
 
 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,7 +65,10 @@ class QueueHandler {
                return true;
        }
        
-       function handle_queue() {
+       function run() {
+               if (!$this->start()) {
+                       return false;
+               }
                $this->log(LOG_INFO, 'checking for queued notices');
                $transport = $this->transport();
                do {
@@ -76,26 +89,31 @@ 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();
-                               $this->idle();
+                               $qi->free();
+                               unset($qi);
+                               $this->idle(0);
                        } else {
                                $this->clear_old_claims();
-                               $start = microtime();
-                               $this->idle();
-                               $used = microtime() - $start;
-                               if ($used < 3000000) {
-                                       usleep(3000000 - $used);
-                               }
+                               $this->idle(5);
                        }       
                } while (true);
+               if (!$this->finish()) {
+                       return false;
+               }
+               return true;
        }
 
-       function idle() {
-               return true;
+       function idle($timeout=0) {
+               if ($timeout>0) {
+                       sleep($timeout);
+               }
        }
        
        function clear_old_claims() {
@@ -103,6 +121,8 @@ class QueueHandler {
                $qi->transport = $this->transport();
                $qi->whereAdd('now() - claimed > '.CLAIM_TIMEOUT);
                $qi->update(DB_DATAOBJECT_WHEREADD_ONLY);
+               $qi->free();
+               unset($qi);
        }
        
        function log($level, $msg) {