/** * Run a polling cycle during idle processing in the input loop. * @return boolean true if we should poll again for more data immediately */ public function poll() { $this->_log(LOG_DEBUG, 'Checking for notices...'); $qi = Queue_item::top($this->activeQueues()); if (empty($qi)) { $this->_log(LOG_DEBUG, 'No notices waiting; idling.'); return false; } $queue = $qi->transport; $item = $this->decode($qi->frame); if ($item) { $rep = $this->logrep($item); $this->_log(LOG_INFO, "Got {$rep} for transport {$queue}"); $handler = $this->getHandler($queue); if ($handler) { if ($handler->handle($item)) { $this->_log(LOG_INFO, "[{$queue}:{$rep}] Successfully handled item"); $this->_done($qi); } else { $this->_log(LOG_INFO, "[{$queue}:{$rep}] Failed to handle item"); $this->_fail($qi); } } else { $this->_log(LOG_INFO, "[{$queue}:{$rep}] No handler for queue {$queue}; discarding."); $this->_done($qi); } } else { $this->_log(LOG_INFO, "[{$queue}] Got empty/deleted item, discarding"); $this->_fail($qi); } return true; }
/** * Run a polling cycle during idle processing in the input loop. * @return boolean true if we should poll again for more data immediately */ public function poll() { //$this->_log(LOG_DEBUG, 'Checking for notices...'); $qi = Queue_item::top($this->activeQueues(), $this->getIgnoredTransports()); if (!$qi instanceof Queue_item) { //$this->_log(LOG_DEBUG, 'No notices waiting; idling.'); return false; } try { $item = $this->decode($qi->frame); } catch (Exception $e) { $this->_log(LOG_INFO, "[{$qi->transport}] Discarding: " . $e->getMessage()); $this->_done($qi); return true; } $rep = $this->logrep($item); $this->_log(LOG_DEBUG, "Got {$rep} for transport {$qi->transport}"); $handler = $this->getHandler($qi->transport); if ($handler) { if ($handler->handle($item)) { $this->_log(LOG_INFO, "[{$qi->transport}:{$rep}] Successfully handled item"); $this->_done($qi); } else { $this->_log(LOG_INFO, "[{$qi->transport}:{$rep}] Failed to handle item"); $this->_fail($qi); } } else { $this->noHandlerFound($qi, $rep); } return true; }
function run() { if (!$this->start()) { return false; } $this->log(LOG_INFO, 'checking for queued notices'); $transport = $this->transport(); do { $qi = Queue_item::top($transport); if ($qi) { $this->log(LOG_INFO, 'Got item enqueued ' . common_exact_date($qi->created)); $notice = Notice::staticGet($qi->notice_id); if ($notice) { $this->log(LOG_INFO, 'broadcasting notice ID = ' . $notice->id); # XXX: what to do if broadcast fails? $result = $this->handle_notice($notice); if (!$result) { $this->log(LOG_WARNING, 'Failed broadcast for notice ID = ' . $notice->id); $orig = $qi; $qi->claimed = null; $qi->update($orig); $this->log(LOG_WARNING, 'Abandoned claim for notice ID = ' . $notice->id); 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(); $qi->free(); unset($qi); $this->idle(0); } else { $this->clear_old_claims(); $this->idle(5); } } while (true); if (!$this->finish()) { return false; } return true; }
function _nextItem($queue, $timeout = null) { $start = time(); $result = null; do { $qi = Queue_item::top($queue); if (!empty($qi)) { $notice = Notice::staticGet('id', $qi->notice_id); if (!empty($notice)) { $result = $notice; } else { $this->_log(LOG_INFO, 'dequeued non-existent notice ' . $notice->id); $qi->delete(); $qi->free(); $qi = null; } } } while (empty($result) && (is_null($timeout) || time() - $start < $timeout)); return $result; }