예제 #1
0
 /**
  * Retry the failed job for given times.
  */
 public function retry()
 {
     $retryTimes = Constant::$RETRY_TIMES;
     $expiredTime = Constant::$FAILED_TIMES_EXPIRED_TIME;
     $jobId = $this->payload['id'];
     if ($retryTimes > 0 && !empty($jobId)) {
         $failedTimes = (int) Resque_Stat::get('job:failed:' . $jobId);
         $enqueuedAt = ($failedTimes + 1) * Constant::$FAILED_JOB_DELAYED_TIME;
         if ($expiredTime > $enqueuedAt) {
             if ($expiredTime > 0 && 0 == $failedTimes) {
                 Resque_Stat::expire('job:failed:' . $jobId, $expiredTime);
             }
             if ($failedTimes < $retryTimes) {
                 $this->recreate($enqueuedAt);
                 Resque_Stat::incr('job:failed:' . $jobId);
             } else {
                 $this->recreate($enqueuedAt, true);
             }
         }
     }
 }
예제 #2
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);
 }
예제 #3
0
 /**
  * Get the amount of failed jobs
  *
  * @param string $workerId
  *            the id of worker
  *
  * @return int
  */
 public function getFailedJobsCount($workerId = null)
 {
     if (!empty($workerId)) {
         return Resque_Stat::get('failed:' . $workerId);
     } else {
         return Resque_Stat::get('failed');
     }
 }