/**
  * Release the job back into the queue.
  *
  * @param  int   $delay
  * @return void
  */
 public function release($delay = 0)
 {
     $priority = Pheanstalk::DEFAULT_PRIORITY;
     $this->pheanstalk->release($this->job, $priority, $delay);
 }
Пример #2
0
 public function releaseJob(JobInterface $job)
 {
     $this->pheanstalk->release($job->getPheanstalkJob());
 }
Пример #3
0
 /**
  * Bury a job
  */
 public function buryAction()
 {
     $server = $this->_getParam("server");
     $tube = $this->_getParam("tube");
     $jobId = $this->_getParam("id");
     try {
         // Connect to the server
         $messageQueue = new Pheanstalk_Pheanstalk($server);
         // Check if the next job in the queue is still the same job
         $stillExists = false;
         try {
             /** @var $nextJob Pheanstalk_Job */
             $nextJob = $messageQueue->peekReady($tube);
             if ($nextJob instanceof Pheanstalk_Job && $nextJob->getId() == $jobId) {
                 $stillExists = true;
             }
         } catch (Exception $e) {
         }
         if ($stillExists) {
             // Try to reserve the job
             /** @var $job Pheanstalk_Job */
             $job = $messageQueue->reserveFromTube($tube, 0);
             // Last check (may have changed since first check)
             if ($job instanceof Pheanstalk_Job) {
                 // Correct job
                 if ($job->getId() == $jobId) {
                     $messageQueue->bury($job);
                     $response = "";
                 } else {
                     // Wrong job, un-reserve
                     $messageQueue->release($job);
                     $response = "There was a error while burying the job, try again.";
                 }
             } else {
                 $this->getResponse()->setHttpResponseCode(500);
                 $response = "No job found in the tube.";
             }
         } else {
             $this->getResponse()->setHttpResponseCode(500);
             $response = "The job can't be found, maybe it has been deleted, delayed or buried.";
         }
     } catch (Exception $e) {
         $this->getResponse()->setHttpResponseCode(500);
         $response = $e->getMessage();
     }
     // Send Json response
     $this->jsonHelper->sendJson($response);
     $this->jsonHelper->getResponse()->sendResponse();
 }
Пример #4
0
function ProcessTests($crawl)
{
    global $beanstalkd;
    $tube = 'har.' . $crawl;
    $pheanstalk = new Pheanstalk_Pheanstalk($beanstalkd);
    do {
        $got_test = true;
        try {
            $job = $pheanstalk->reserveFromTube($tube, 0);
            if ($job !== false) {
                $id = $job->getData();
                if (ProcessTest($id)) {
                    $pheanstalk->delete($job);
                } else {
                    $pheanstalk->release($job);
                }
            } else {
                $got_test = false;
            }
        } catch (Exception $e) {
            if ($e->getMessage() == 'Server reported NOT_FOUND') {
                $got_test = false;
            } else {
                unset($pheanstalk);
                sleep(1);
                $pheanstalk = new Pheanstalk_Pheanstalk($beanstalkd);
            }
        }
    } while ($got_test);
    unset($pheanstalk);
}