public function clearQueue($queue) { while ($job = $this->queue->reserve(0)) { $this->queue->delete($job); } }
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) { $jobDispatcher->setQueueName($options->queue); } // Log all to stdout. $log = $application->getBootstrap()->logger; $log->addWriter(new Zend_Log_Writer_Stream('php://output'));
/** * Reserves a job * * @param integer $timeout timeout in seconds * @return bool|object|\Pheanstalk_Job */ public function reserve($timeout) { return $this->pheanstalk->reserve($timeout); }