public function restGetQueueClear()
 {
     $this->changeViewModel('json');
     $queue = $this->params()->fromQuery('queue', 'default');
     $res = \Resque_Stat::clear($queue);
     return new JsonModel(array('res' => $res));
 }
Beispiel #2
0
 /**
  * Mark the current job as having failed.
  *
  * @param $exception
  */
 public function fail($exception)
 {
     Resque_Event::trigger('onFailure', array('exception' => $exception, 'job' => $this));
     $this->updateStatus(Resque_Job_Status::STATUS_FAILED);
     Resque_Failure::create($this->payload, $exception, $this->worker, $this->queue);
     Resque_Stat::incr('failed');
     Resque_Stat::incr('failed:' . $this->worker);
 }
Beispiel #3
0
 public function testFailedJobExceptionsAreCaught()
 {
     $payload = array('class' => 'Failing_Job', 'id' => 'randomId', 'args' => null);
     $job = new Resque_Job('jobs', $payload);
     $job->worker = $this->worker;
     $this->worker->perform($job);
     $this->assertEquals(1, Resque_Stat::get('failed'));
     $this->assertEquals(1, Resque_Stat::get('failed:' . $this->worker));
 }
Beispiel #4
0
 public function testGetUnknownStatReturns0()
 {
     $this->assertEquals(0, Resque_Stat::get('test_get_unknown'));
 }
Beispiel #5
0
 /**
  * Print some stats about the workers
  *
  * @return  void
  */
 public function stats()
 {
     $workers = call_user_func(array($this->ResqueStats, 'getWorkers'));
     // List of all queues
     $queues = array_unique(call_user_func(array($this->ResqueStats, 'getQueues')));
     // List of queues monitored by a worker
     $activeQueues = array();
     foreach ($workers as $worker) {
         $tokens = explode(':', $worker);
         $activeQueues = array_merge($activeQueues, explode(',', array_pop($tokens)));
     }
     $this->outputTitle('Resque statistics');
     $this->output->outputLine();
     $this->output->outputLine('Jobs Stats', 'subtitle');
     $this->output->outputLine('   ' . sprintf('Processed Jobs : %10s', number_format(\Resque_Stat::get('processed'))));
     $this->output->outputLine('   ' . sprintf('Failed Jobs    : %10s', number_format(\Resque_Stat::get('failed'))), 'failure');
     if ($this->runtime['Scheduler']['enabled'] === true) {
         $this->output->outputLine('   ' . sprintf('Scheduled Jobs : %10s', number_format(\ResqueScheduler\Stat::get())));
     }
     $this->output->outputLine();
     $count = array();
     $this->output->outputLine('Queues Stats', 'subtitle');
     for ($i = count($queues) - 1; $i >= 0; --$i) {
         $count[$queues[$i]] = call_user_func_array(array($this->ResqueStats, 'getQueueLength'), array($queues[$i]));
         if (!in_array($queues[$i], $activeQueues) && $count[$queues[$i]] == 0) {
             unset($queues[$i]);
         }
     }
     $this->output->outputLine('   ' . sprintf('Queues count : %d', count($queues)));
     foreach ($queues as $queue) {
         $this->output->outputText(sprintf("\t- %-20s : %10s pending jobs", $queue, number_format($count[$queue])));
         if (!in_array($queue, $activeQueues)) {
             $this->output->outputText(' (unmonitored queue)', 'failure');
         }
         $this->output->outputText("\n");
     }
     $this->output->outputLine();
     $this->output->outputLine('Workers Stats', 'subtitle');
     $this->output->outputLine('  Active Workers : ' . count($workers));
     $schedulerWorkers = array();
     if (!empty($workers)) {
         $pausedWorkers = call_user_func(array($this->ResqueStatus, 'getPausedWorker'));
         foreach ($workers as $worker) {
             if ($this->runtime['Scheduler']['enabled'] === true && $this->ResqueStatus->isSchedulerWorker($worker)) {
                 $schedulerWorkers[] = $worker;
                 continue;
             }
             $this->output->outputText('    Worker : ' . $worker, 'bold');
             if (in_array((string) $worker, $pausedWorkers)) {
                 $this->output->outputText(' (Paused)', 'success');
             }
             $this->output->outputText("\n");
             $startDate = call_user_func_array(array($this->ResqueStats, 'getWorkerStartDate'), array($worker));
             $this->output->outputLine('     - Started on     : ' . $startDate);
             $this->output->outputLine('     - Uptime         : ' . $this->formatDateDiff(new \DateTime($startDate)));
             $this->output->outputLine('     - Processed Jobs : ' . $worker->getStat('processed'));
             $worker->getStat('failed') == 0 ? $this->output->outputLine('     - Failed Jobs    : ' . $worker->getStat('failed')) : $this->output->outputLine('     - Failed Jobs    : ' . $worker->getStat('failed'), 'failure');
         }
     }
     $this->output->outputLine("\n");
     if (!empty($schedulerWorkers)) {
         $this->output->outputText(ucwords('    scheduler worker'), 'bold');
         if (in_array((string) $schedulerWorkers[0], $pausedWorkers)) {
             $this->output->outputText(' (Paused)', 'success');
         }
         $this->output->outputText("\n");
         foreach ($schedulerWorkers as $worker) {
             $schedulerWorker = new \ResqueScheduler\ResqueScheduler();
             $delayedJobCount = $schedulerWorker->getDelayedQueueScheduleSize();
             $this->output->outputLine('    - Started on      : ' . call_user_func_array(array($this->ResqueStats, 'getWorkerStartDate'), array($worker)));
             $this->output->outputLine('    - Delayed Jobs    : ' . number_format($delayedJobCount));
             if ($delayedJobCount > 0) {
                 $this->output->outputLine('    - Next Job on     : ' . strftime('%a %b %d %H:%M:%S %Z %Y', $schedulerWorker->nextDelayedTimestamp()));
             }
         }
         $this->output->outputLine("\n");
     } elseif ($this->runtime['Scheduler']['enabled'] === true) {
         $jobsCount = \ResqueScheduler\ResqueScheduler::getDelayedQueueScheduleSize();
         if ($jobsCount > 0) {
             $this->output->outputLine("    ************ " . 'Alert' . " ************", 'failure');
             $this->output->outputLine("    " . 'The Scheduler Worker is not running', 'bold');
             $this->output->outputLine("    " . 'But there is still ' . number_format($jobsCount) . ' scheduled jobs left in its queue');
             $this->output->outputLine("    ********************************", 'failure');
             $this->output->outputLine("\n");
         }
     }
 }
Beispiel #6
0
 /**
  * Get a statistic belonging to this worker.
  *
  * @param string $stat Statistic to fetch.
  * @return int Statistic value.
  */
 public function getStat($stat)
 {
     return Resque_Stat::get($stat . ':' . $this);
 }
Beispiel #7
0
 public function testWorkerFailsUncompletedJobsOnExit()
 {
     $worker = new Resque_Worker('jobs');
     $worker->setLogger(new Resque_Log());
     $worker->registerWorker();
     $payload = array('class' => 'Test_Job');
     $job = new Resque_Job('jobs', $payload);
     $worker->workingOn($job);
     $worker->unregisterWorker();
     $this->assertEquals(1, Resque_Stat::get('failed'));
 }
 /**
  * Delete a statistic with the given name.
  *
  * @param string $stat The name of the statistic to delete.
  * @return boolean True if successful, false if not.
  */
 public static function clear($stat = self::KEYNAME)
 {
     return parent::clear($stat);
 }
Beispiel #9
0
 /**
  * Print some stats about the workers
  */
 protected function stats()
 {
     $this->outputTitle('Workers statistics');
     $this->output->outputLine();
     $this->output->outputLine('Jobs Stats', 'subtitle');
     $this->output->outputLine("   Processed Jobs : " . \Resque_Stat::get('processed'));
     $this->output->outputLine("   Failed Jobs    : " . \Resque_Stat::get('failed'), 'failure');
     $this->output->outputLine();
     $this->output->outputLine('Workers Stats', 'subtitle');
     $workers = \Resque_Worker::all();
     $this->output->outputLine("   Active Workers : " . count($workers));
     if (!empty($workers)) {
         foreach ($workers as $worker) {
             $this->output->outputLine("    Worker : " . $worker, 'bold');
             $this->output->outputLine("     - Started on     : " . \Resque::Redis()->get('worker:' . $worker . ':started'));
             $this->output->outputLine("     - Uptime         : " . $this->formatDateDiff(new \DateTime(\Resque::Redis()->get('worker:' . $worker . ':started'))));
             $this->output->outputLine("     - Processed Jobs : " . $worker->getStat('processed'));
             $worker->getStat('failed') == 0 ? $this->output->outputLine("     - Failed Jobs    : " . $worker->getStat('failed')) : $this->output->outputLine("     - Failed Jobs    : " . $worker->getStat('failed'), 'failure');
         }
     }
     $this->output->outputLine("\n");
 }
Beispiel #10
0
 public function testResumedWorkerPicksUpJobs()
 {
     return self::markTestSkipped();
     $this->worker->setLogger(new Resque_Log());
     $this->worker->pause();
     Resque::enqueue('jobs', 'Test_Job');
     $this->worker->work(0);
     $this->assertEquals(0, Resque_Stat::get('processed'));
     $this->worker->unPauseProcessing();
     $this->worker->work(0);
     $this->assertEquals(1, Resque_Stat::get('processed'));
 }
Beispiel #11
0
 /**
  * Display usefull stats about the workers.
  *
  * Note: The workers status is conveniently stored by ResqueStatus.
  *
  * @return void
  * @see ResqueStatus\ResqueStatus::isSchedulerWorker()
  * @see ResqueStatus\ResqueStatus::getPausedWorker()
  */
 public function stats()
 {
     $ResqueStatus = $this->ResqueStatus;
     $workers = call_user_func(CakeResqueShell::$cakeResque . '::getWorkers');
     // List of all queues
     $queues = array_unique(call_user_func(CakeResqueShell::$cakeResque . '::getQueues'));
     // List of queues monitored by a worker
     $activeQueues = array();
     foreach ($workers as $worker) {
         $workerParams = explode(':', $worker);
         $activeQueues = array_merge($activeQueues, explode(',', array_pop($workerParams)));
     }
     $this->out("\n");
     $this->out('<info>' . __d('cake_resque', 'Resque Statistics') . '</info>');
     $this->hr();
     $this->out("\n");
     $this->out('<info>' . __d('cake_resque', 'Jobs Stats') . '</info>');
     $this->out('   ' . __d('cake_resque', 'Processed Jobs : %12s', number_format(Resque_Stat::get('processed'))));
     $this->out('   <warning>' . __d('cake_resque', 'Failed Jobs    : %12s', number_format(Resque_Stat::get('failed'))) . '</warning>');
     if (Configure::read('CakeResque.Scheduler.enabled') === true) {
         $this->out('   ' . __d('cake_resque', 'Scheduled Jobs : %12s', number_format(ResqueScheduler\Stat::get())));
     }
     $this->out("\n");
     $count = array();
     $this->out('<info>' . __d('cake_resque', 'Queues Stats') . '</info>');
     for ($i = count($queues) - 1; $i >= 0; --$i) {
         $count[$queues[$i]] = call_user_func_array(CakeResqueShell::$cakeResque . '::getQueueSize', array($queues[$i]));
         if (!in_array($queues[$i], $activeQueues) && $count[$queues[$i]] == 0) {
             unset($queues[$i]);
         }
     }
     $this->out('   ' . __d('cake_resque', 'Queues count : %d', count($queues)));
     foreach ($queues as $queue) {
         $this->out(sprintf("\t- %-15s : %12s %s", $queue, number_format($count[$queue]), __dn('cake_resque', 'pending job', 'pending jobs', $count[$queue]) . (!in_array($queue, $activeQueues) ? " <error>(unmonitored queue)</error>" : '')));
     }
     $this->out("\n");
     $this->out('<info>' . __d('cake_resque', 'Workers Stats') . '</info>');
     $this->out('   ' . __d('cake_resque', 'Workers count : %s', count($workers)));
     $pausedWorkers = $ResqueStatus->getPausedWorker();
     $schedulerWorkers = array();
     if (!empty($workers)) {
         $this->out("\t<info>" . strtoupper(__d('cake_resque', 'regular workers')) . "</info>");
         foreach ($workers as $worker) {
             if (Configure::read('CakeResque.Scheduler.enabled') === true && $ResqueStatus->isSchedulerWorker($worker)) {
                 $schedulerWorkers[] = $worker;
                 continue;
             }
             $this->out("\t* <bold>" . (string) $worker . '</bold>' . (in_array((string) $worker, $pausedWorkers) ? ' <warning>(' . __d('cake_resque', 'paused') . ')</warning>' : ''));
             $this->out("\t   - " . __d('cake_resque', 'Started on') . "     : " . call_user_func(CakeResqueShell::$cakeResque . '::getWorkerStartDate', $worker));
             $this->out("\t   - " . __d('cake_resque', 'Processed Jobs') . " : " . $worker->getStat('processed'));
             $worker->getStat('failed') == 0 ? $this->out("\t   - " . __d('cake_resque', 'Failed Jobs') . "    : " . $worker->getStat('failed')) : $this->out("\t   - <warning>" . __d('cake_resque', 'Failed Jobs') . "    : " . $worker->getStat('failed') . "</warning>");
         }
     }
     $this->out("\n");
     if (!empty($schedulerWorkers)) {
         $this->out("\t<info>" . strtoupper(__d('cake_resque', 'scheduler worker')) . "</info>" . (in_array((string) $schedulerWorkers[0], $pausedWorkers) ? ' <warning>(' . __d('cake_resque', 'paused') . ')</warning>' : ''));
         foreach ($schedulerWorkers as $worker) {
             $schedulerWorker = new ResqueScheduler\ResqueScheduler();
             $delayedJobCount = $schedulerWorker->getDelayedQueueScheduleSize();
             $this->out("\t   - " . __d('cake_resque', 'Started on') . "     : " . call_user_func(CakeResqueShell::$cakeResque . '::getWorkerStartDate', $worker));
             $this->out("\t   - " . __d('cake_resque', 'Delayed Jobs') . "   : " . $delayedJobCount);
             if ($delayedJobCount > 0) {
                 $this->out("\t   - " . __d('cake_resque', 'Next Job on') . "    : " . strftime('%a %b %d %H:%M:%S %Z %Y', $schedulerWorker->nextDelayedTimestamp()));
             }
         }
         $this->out("\n");
     } elseif (Configure::read('CakeResque.Scheduler.enabled') === true) {
         $jobsCount = ResqueScheduler\ResqueScheduler::getDelayedQueueScheduleSize();
         if ($jobsCount > 0) {
             $this->out("\t<error>************ " . __d('cake_resque', 'Alert') . " ************</error>");
             $this->out("\t<bold>" . __d('cake_resque', 'The Scheduler Worker is not running') . "</bold>");
             $this->out("\t" . __d('cake_resque', 'But there is still <bold>%d</bold> scheduled jobs left in its queue', $jobsCount));
             $this->out("\t<error>********************************</error>");
             $this->out("\n");
         }
     }
 }
 /**
  * Mark the current job as having failed.
  *
  * @param $exception
  */
 public function fail($exception)
 {
     Resque_Event::trigger('onFailure', array('exception' => $exception, 'job' => $this));
     // job的状态更新成failed
     $this->updateStatus(Resque_Job_Status::STATUS_FAILED);
     require_once dirname(__FILE__) . '/Failure.php';
     // 记录信息到failed队列中
     Resque_Failure::create($this->payload, $exception, $this->worker, $this->queue);
     // 失败状态的个数+1
     Resque_Stat::incr('failed');
     Resque_Stat::incr('failed:' . $this->worker);
 }
Beispiel #13
0
 /**
  * Print some stats about the workers
  *
  * @return  void
  */
 public function stats()
 {
     $workers = call_user_func(array($this->ResqueStats, 'getWorkers'));
     // List of all queues
     $queues = array_unique(call_user_func(array($this->ResqueStats, 'getQueues')));
     // List of queues monitored by a worker
     $activeQueues = array();
     foreach ($workers as $worker) {
         $tokens = explode(':', $worker);
         $activeQueues = array_merge($activeQueues, explode(',', array_pop($tokens)));
     }
     $this->outputTitle('Resque statistics');
     $this->output->outputLine();
     $this->output->outputLine('Jobs Stats', 'subtitle');
     $this->output->outputLine('   ' . sprintf('Processed Jobs : %10s', number_format(\Resque_Stat::get('processed'))));
     $this->output->outputLine('   ' . sprintf('Failed Jobs    : %10s', number_format(\Resque_Stat::get('failed'))), 'failure');
     $this->output->outputLine();
     $count = array();
     $this->output->outputLine('Queues Stats', 'subtitle');
     for ($i = count($queues) - 1; $i >= 0; --$i) {
         $count[$queues[$i]] = call_user_func_array(array($this->ResqueStats, 'getQueueLength'), array($queues[$i]));
         if (!in_array($queues[$i], $activeQueues) && $count[$queues[$i]] == 0) {
             unset($queues[$i]);
         }
     }
     $this->output->outputLine('   ' . sprintf('Queues count : %d', count($queues)));
     foreach ($queues as $queue) {
         $this->output->outputText(sprintf("\t- %-20s : %10s pending jobs", $queue, number_format($count[$queue])));
         if (!in_array($queue, $activeQueues)) {
             $this->output->outputText(' (unmonitored queue)', 'failure');
         }
         $this->output->outputText("\n");
     }
     $this->output->outputLine();
     $this->output->outputLine('Workers Stats', 'subtitle');
     $this->output->outputLine('  Active Workers : ' . count($workers));
     if (!empty($workers)) {
         $pausedWorkers = call_user_func(array($this->ResqueStatus, 'getPausedWorker'));
         foreach ($workers as $worker) {
             $this->output->outputText('    Worker : ' . $worker, 'bold');
             if (in_array((string) $worker, $pausedWorkers)) {
                 $this->output->outputText(' (Paused)', 'success');
             }
             $this->output->outputText("\n");
             $startDate = call_user_func_array(array($this->ResqueStats, 'getWorkerStartDate'), array($worker));
             $this->output->outputLine('     - Started on     : ' . $startDate);
             $this->output->outputLine('     - Uptime         : ' . $this->formatDateDiff(new \DateTime($startDate)));
             $this->output->outputLine('     - Processed Jobs : ' . $worker->getStat('processed'));
             $worker->getStat('failed') == 0 ? $this->output->outputLine('     - Failed Jobs    : ' . $worker->getStat('failed')) : $this->output->outputLine('     - Failed Jobs    : ' . $worker->getStat('failed'), 'failure');
         }
     }
     $this->output->outputLine("\n");
 }