protected function createJob($label, $data = array()) { $job = new Opus_Job(); $job->setLabel($label); $job->setData($data); $this->jobIds[] = $job->store(); }
public function setUp() { parent::setUp(); $config = Zend_Registry::get('Zend_Config'); $this->__configBackup = $config; $config->merge(new Zend_Config(array('runjobs' => array('asynchronous' => true)))); $this->assertEquals(0, Opus_Job::getCount(Opus_Job::STATE_FAILED), 'test data changed.'); for ($i = 0; $i < 10; $i++) { $job = new Opus_Job(); $job->setLabel('testjob' . ($i < 5 ? 1 : 2)); $job->setData(array('documentId' => $i, 'task' => 'get-me-a-coffee')); $job->setState(Opus_Job::STATE_FAILED); $this->jobIds[] = $job->store(); } }
public function createJob() { $job = new Opus_Job(); $job->setLabel(Opus_Job_Worker_ConsistencyCheck::LABEL); if (!$this->featureDisabled) { // Queue job (execute asynchronously) // skip creating job if equal job already exists if (true === $job->isUniqueInQueue()) { $job->store(); return $job->getId(); } return true; } // Execute job immediately (synchronously): currently NOT supported try { $worker = new Opus_Job_Worker_ConsistencyCheck(); $worker->setLogger($this->logger); $worker->work($job); } catch (Exception $exc) { $this->logger->err($exc); } return false; }
/** * Helper method to add document to index. * * @param Opus_Document $document * @return void */ private function addDocumentToIndex(Opus_Document $document) { $log = Zend_Registry::get('Zend_Log'); // create job if asynchronous is set if (isset($this->config->runjobs->asynchronous) && $this->config->runjobs->asynchronous) { $log->debug(__METHOD__ . ': ' . 'Adding index job for document ' . $document->getId() . '.'); $job = new Opus_Job(); $job->setLabel(Opus_Job_Worker_IndexOpusDocument::LABEL); $job->setData(array('documentId' => $document->getId(), 'task' => 'index')); // skip creating job if equal job already exists if (true === $job->isUniqueInQueue()) { $job->store(); } else { $log->debug(__METHOD__ . ': ' . 'Indexing job for document ' . $document->getId() . ' already exists!'); } } else { $log->debug(__METHOD__ . ': ' . 'Index document ' . $document->getId() . '.'); try { $indexer = new Opus_SolrSearch_Index_Indexer(); $indexer->addDocumentToEntryIndex($document); $indexer->commit(); } catch (Opus_SolrSearch_Index_Exception $e) { $log->debug(__METHOD__ . ': ' . 'Indexing document ' . $document->getId() . ' failed: ' . $e->getMessage()); } catch (InvalidArgumentException $e) { $log->warn(__METHOD__ . ': ' . $e->getMessage()); } } }
private function scheduleNotification($subject, $message, $recipients) { if (empty($recipients)) { $this->logger->warn("No recipients could be determined for email notification: skip operation"); return; } $addressesUsed = array(); foreach ($recipients as $recipient) { if (!in_array($recipient['address'], $addressesUsed)) { $job = new Opus_Job(); $job->setLabel(Opus_Job_Worker_MailNotification::LABEL); $job->setData(array('subject' => $subject, 'message' => $message, 'users' => array($recipient))); if (isset($this->config->runjobs->asynchronous) && $this->config->runjobs->asynchronous) { // Queue job (execute asynchronously) // skip creating job if equal job already exists if (true === $job->isUniqueInQueue()) { $job->store(); } } else { // Execute job immediately (synchronously) try { $mail = new Opus_Job_Worker_MailNotification($this->logger, false); $mail->work($job); } catch (Exception $exc) { $this->logger->err("Email notification failed: " . $exc); } } array_push($addressesUsed, $recipient['address']); } } }
/** * * @param Matheon_Model_Document $document * @param array $recipient * @return void */ private function __sendPublishNotification($document, $recipient) { $config = $this->getConfig(); $baseUrlFiles = $this->view->serverUrl() . '/opus4-matheon/files'; $job = new Opus_Job(); $job->setLabel(Opus_Job_Worker_MailNotification::LABEL); $job->setData(array('subject' => $document->renderPublishMailSubject(), 'message' => $document->renderPublishMailBody($this->view->fullUrl(), $baseUrlFiles), 'users' => $recipient)); //throw new Exception(var_export($job, true)); if (isset($config->runjobs->asynchronous) && $config->runjobs->asynchronous) { // Queue job (execute asynchronously) // skip creating job if equal job already exists if (true === $job->isUniqueInQueue()) { $job->store(); } return true; } // Execute job immediately (synchronously) try { $mail = new Opus_Job_Worker_MailNotification($this->getLogger()); $mail->work($job); } catch (Exception $exc) { $this->getLogger()->err($exc); } return true; }