Exemplo n.º 1
0
 public function fetchJob($timeout = null)
 {
     $pheanstalkJob = $this->pheanstalk->watch($this->tube)->ignore('default')->reserve($timeout);
     if (!$pheanstalkJob) {
         return null;
     }
     $job = new PheanstalkQueueJob(unserialize($pheanstalkJob->getData()), $pheanstalkJob);
     $job->setQueue($this);
     return $job;
 }
Exemplo n.º 2
0
 public function Run()
 {
     $this->Log("Beginning to Run");
     // We want to catch any errors in case something goes really wrong and cleanly exit
     try {
         /************* MAGIC IS HERE **************
          * This is where the magic happens
          * The worker will loop forever while $this->run
          * is true.
          ******************************************/
         while ($this->run) {
             // Report our current status
             $this->status = 'listening';
             $this->Report();
             // Listen to a beanstalk tube
             $job = $this->beanstalk->watch('system')->watch('queue')->ignore('default')->reserve(10);
             // When a job exists, process the job.
             if ($job) {
                 $this->ProcessJob($job);
             }
             // Echo a "." so we know the worker isn't frozen in the logs.
             echo ".";
             $this->status = 'checking';
             $this->Report();
             // Check the status of the worker to see if we need to stop running.
             $this->CheckStatus();
         }
     } catch (Exception $ex) {
         $this->Log("Exception Caught: " . $ex->getMessage());
         var_dump($ex->getTrace());
     }
     // Cleanup any status & connections
     $this->Cleanup();
     // Stop the worker from working
     return;
 }
Exemplo n.º 3
0
{
    switch ($signal) {
        case SIGINT:
            throw new Omeka_Job_Worker_InterruptException("Caught SIGINT, shutting down.");
            break;
        default:
            break;
    }
}
pcntl_signal(SIGINT, "handle_signal");
$application->bootstrap(array('Logger'));
$host = isset($options->host) ? $options->host : '127.0.0.1';
$port = isset($options->port) ? $options->port : 11300;
$pheanstalk = new Pheanstalk_Pheanstalk("{$host}:{$port}");
if (isset($options->queue) && $options->queue != 'default') {
    $pheanstalk->watch($options->queue)->ignore('default');
}
// Reserving a job BEFORE bootstrapping the database will ensure that there are
// never any MySQL timeout issues and help prevent any number of other database
// usage-related problems.
$pheanJob = $pheanstalk->reserve();
if (!$pheanJob) {
    // Timeouts can occur when reserving a job, so this must be taken
    // into account.  No cause for alarm.
    echo "Beanstalk worker timed out when reserving a job.";
    exit(0);
}
$application->bootstrap(array('Config', 'Db', 'Filederivatives', 'Locale', 'Options', 'Pluginbroker', 'Plugins', 'Jobs', 'Storage', 'Mail', 'View'));
// resend() must send jobs to the original queue by default.
$jobDispatcher = Zend_Registry::get('job_dispatcher');
if ($options->queue) {
 /**
  * Watches a tube
  *
  * @param string $tube
  * @return $this
  */
 public function watch($tube)
 {
     $this->pheanstalk->watch($tube);
     return $this;
 }