コード例 #1
0
ファイル: MetadataImport.php プロジェクト: alexukua/opus4
 /**
  * Perfom work.
  *
  * @param Opus_Job $job Job description and attached data.
  * @return array Array of Jobs to be newly created.
  */
 public function work(Opus_Job $job)
 {
     if ($job->getLabel() != $this->getActivationLabel()) {
         throw new Opus_Job_Worker_InvalidJobException($job->getLabel() . " is not a suitable job for this worker.");
     }
     $data = $job->getData();
     if (!(is_object($data) && isset($data->xml) && !is_null($data->xml))) {
         throw new Opus_Job_Worker_InvalidJobException("Incomplete or missing data.");
     }
     if (null !== $this->_logger) {
         $this->_logger->debug("Importing Metadata:\n" . $data->xml);
     }
     $importer = new Opus_Util_MetadataImport($data->xml);
     $importer->run();
 }
コード例 #2
0
ファイル: ConsistencyCheck.php プロジェクト: alexukua/opus4
 /**
  * Load all published documents from database and check consistency.
  * A document is considered as inconsistent, if
  *
  * - it exists in database, but does not exist in Solr index
  * - it exists in Solr index, but does not exist in database or exists
  *   but with server_state != published
  * - it exists both in database and Solr index, but server_date_modified
  *   timestamps do not coincide
  *
  * @param Opus_Job $job Job description and attached data.
  * @return void
  */
 public function work(Opus_Job $job)
 {
     // make sure we have the right job
     if ($job->getLabel() != $this->getActivationLabel()) {
         throw new Opus_Job_Worker_InvalidJobException($job->getLabel() . " is not a suitable job for this worker.");
     }
     $lockFile = $this->logfilePath . '.lock';
     if (file_exists($lockFile)) {
         unlink($lockFile);
     }
     touch($lockFile);
     $consistencyChecker = new Opus_Util_ConsistencyCheck($this->_logger);
     $consistencyChecker->run();
     unlink($lockFile);
 }
コード例 #3
0
ファイル: IndexOpusDocument.php プロジェクト: alexukua/opus4
 /**
  * Load a document from database and optional file(s) and index them,
  * or remove document from index (depending on job)
  *
  * @param Opus_Job $job Job description and attached data.
  * @return void
  */
 public function work(Opus_Job $job)
 {
     // make sure we have the right job
     if ($job->getLabel() != $this->getActivationLabel()) {
         throw new Opus_Job_Worker_InvalidJobException($job->getLabel() . " is not a suitable job for this worker.");
     }
     $this->_job = $job;
     $data = $job->getData();
     if (!(is_object($data) && isset($data->documentId) && isset($data->task))) {
         throw new Opus_Job_Worker_InvalidJobException("Incomplete or missing data.");
     }
     if (null !== $this->_logger) {
         $this->_logger->info('Indexing document with ID: ' . $data->documentId . '.');
     }
     // create index document or remove index, depending on task
     if ($data->task === 'index') {
         $document = new Opus_Document($data->documentId);
         $this->getIndex()->addDocumentToEntryIndex($document)->commit();
     } else {
         if ($data->task === 'remove') {
             $this->getIndex()->removeDocumentFromEntryIndexById($data->documentId)->commit();
         } else {
             throw new Opus_Job_Worker_InvalidJobException("unknown task '{$data->task}'.");
         }
     }
 }
コード例 #4
0
ファイル: Runner.php プロジェクト: alexukua/opus4
 /**
  * Execute a job and remove it from the jobs table on success.
  *
  * @param Opus_Job $job Job description model.
  * @return boolean Returns true if a job is consumend false if not
  */
 protected function consume(Opus_Job $job)
 {
     $label = $job->getLabel();
     if ($job->getState() !== null) {
         return false;
     }
     if (array_key_exists($label, $this->_workers)) {
         $worker = $this->_workers[$label];
         if (null !== $this->_logger) {
             $this->_logger->info('Processing ' . $label);
         }
         $job->setState(Opus_Job::STATE_PROCESSING);
         $job->store();
         try {
             $worker->setLogger($this->_logger);
             $worker->work($job);
             $job->delete();
             sleep($this->_delay);
         } catch (Exception $ex) {
             if (null !== $this->_logger) {
                 $msg = get_class($worker) . ': ' . $ex->getMessage();
                 $this->_logger->err($msg);
             }
             $job->setErrors(json_encode(array('exception' => get_class($ex), 'message' => $ex->getMessage(), 'trace' => $ex->getTraceAsString())));
             $job->setState(Opus_Job::STATE_FAILED);
             $job->store();
             return false;
         }
         return true;
     }
     return false;
 }