Esempio n. 1
0
 public function JobError()
 {
     $this->Log("Error! Uknown Job! Job ID: " . $this->job->getId());
     $this->Log("Job Data: " . $this->job->getData());
     $this->Log("Burying Job!");
     $this->beanstalk->bury($this->job);
 }
 /**
  * Bury the job in the queue.
  *
  * @return void
  */
 public function bury()
 {
     $this->pheanstalk->bury($this->job);
 }
 /**
  * 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();
 }