/**
  * {@inheritDoc}
  */
 public function boot(ViewFactory $viewFactory, CacheRepository $cache)
 {
     // Define views path
     $this->loadViewsFrom(__DIR__ . '/../resources/views', 'queue-monitor');
     // Composer for the status views
     $composer = function ($view) use($cache) {
         $queues = [];
         foreach ($cache->get(QueueMonitor::QUEUES_CACHE_KEY, []) as $queueName) {
             $status = QueueStatus::get($queueName);
             if (!$status) {
                 $status = new QueueStatus($queueName, QueueStatus::ERROR, false);
                 $status->setMessage("Status not found in cache; is a cron job set up and running?");
             }
             $queues[$queueName] = $status;
         }
         $view->withQueues($queues);
     };
     $viewFactory->composer('queue-monitor::status', $composer);
     $viewFactory->composer('queue-monitor::status-json', $composer);
 }
 /**
  * Cache the fact that a queue check has been queued, and queue the check
  *
  * @return void
  */
 public function queueCheck()
 {
     $status = new QueueStatus($this->queueName, QueueStatus::PENDING);
     $status->save();
     Queue::pushOn($this->queueName, new Job($this->queueName, $this->startTime));
 }
Example #3
0
 /**
  * Execute the job
  *
  * @param Log $log
  * @return void
  */
 public function handle(Log $log)
 {
     $log->debug("Handling check job for queue '{$this->queueName}', queued at {$this->startTime}");
     $status = QueueStatus::get($this->queueName);
     if (!$status) {
         $message = "Queue status was not found in cache, yet queued job ran; is the cache correctly configured?";
         $log->error($message);
         $status = new QueueStatus($this->queueName, QueueStatus::ERROR, false);
         $status->setMessage($message);
         $status->setEndTime();
         $status->save();
     } elseif (!$status->isPending()) {
         $log->warning("Non-pending status for check for queue '{$this->queueName}' found in the cache; ignoring: " . $status);
     } elseif (!$status->getStartTime() || $status->getStartTime()->ne($this->startTime)) {
         $log->warning("Pending status for check for queue '{$this->queueName}' found in the cache with mismatching time (expected {$this->startTime}, found {$status->getStartTime()}); ignoring: " . $status);
     } else {
         $log->debug("Successful queue check for queue '{$this->queueName}'");
         $status->setStatus(QueueStatus::OK);
         $status->setEndTime();
         $status->save();
     }
 }