Пример #1
0
 public function testRun()
 {
     //Create 2 jobLogs, and set one with a date over a week ago (8 days ago) for the endDateTime
     $eightDaysAgoTimestamp = DateTimeUtil::convertTimestampToDbFormatDateTime(time() - 60 * 60 * 24 * 8);
     $jobLog = new JobLog();
     $jobLog->type = 'Monitor';
     $jobLog->startDateTime = $eightDaysAgoTimestamp;
     $jobLog->endDateTime = $eightDaysAgoTimestamp;
     $jobLog->status = JobLog::STATUS_COMPLETE_WITHOUT_ERROR;
     $jobLog->isProcessed = false;
     $jobLog->save();
     $jobLog2 = new JobLog();
     $jobLog2->type = 'ImportCleanup';
     $jobLog2->startDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time());
     $jobLog2->endDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time());
     $jobLog2->status = JobLog::STATUS_COMPLETE_WITHOUT_ERROR;
     $jobLog2->isProcessed = false;
     $jobLog2->save();
     $sql = 'select count(*) count from item';
     $row = R::getRow($sql);
     $this->assertEquals(4, $row['count']);
     $job = new JobLogCleanupJob();
     $this->assertTrue($job->run());
     $jobLogs = JobLog::getAll();
     $this->assertEquals(1, count($jobLogs));
     $this->assertEquals($jobLog2->id, $jobLogs[0]->id);
     $sql = 'select count(*) count from item';
     $row = R::getRow($sql);
     $this->assertEquals(3, $row['count']);
 }
Пример #2
0
 public function testGetByType()
 {
     Yii::app()->user->userModel = User::getByUsername('super');
     $jobLog = new JobLog();
     $jobLog->type = 'Monitor';
     $jobLog->startDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time());
     $jobLog->endDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time());
     $jobLog->status = JobLog::STATUS_COMPLETE_WITHOUT_ERROR;
     $jobLog->isProcessed = false;
     $this->assertTrue($jobLog->save());
     $jobLog = new JobLog();
     $jobLog->type = 'Monitor';
     $jobLog->startDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time());
     $jobLog->endDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time());
     $jobLog->status = JobLog::STATUS_COMPLETE_WITHOUT_ERROR;
     $jobLog->isProcessed = false;
     $this->assertTrue($jobLog->save());
     $jobLog = new JobLog();
     $jobLog->type = 'SomethingElse';
     $jobLog->startDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time());
     $jobLog->endDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time());
     $jobLog->status = JobLog::STATUS_COMPLETE_WITHOUT_ERROR;
     $jobLog->isProcessed = false;
     $this->assertTrue($jobLog->save());
     $jobLogs = JobLog::getByType('Monitor');
     $this->assertCount(2, $jobLogs);
     $jobLogs = JobLog::getByType('Monitor', 1);
     $this->assertCount(1, $jobLogs);
     $jobLogs = JobLog::getByType('SomethingElse');
     $this->assertCount(1, $jobLogs);
     $jobLogs = JobLog::getByType('SomethingElse', 1);
     $this->assertCount(1, $jobLogs);
 }
Пример #3
0
 /**
  * Special method to load up many job logs to view paginiation, modal,  etc. in job log modal view
  */
 public function actionLoadManyJobLogs()
 {
     if (Yii::app()->user->userModel->username != 'super') {
         throw new NotSupportedException();
     }
     echo 'Creating jobs for CurrencyRatesUpdate' . "\n";
     for ($i = 0; $i < 10; $i++) {
         $jobLog = new JobLog();
         $jobLog->type = 'CurrencyRatesUpdate';
         $jobLog->startDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time());
         $jobLog->endDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time());
         $jobLog->status = JobLog::STATUS_COMPLETE_WITHOUT_ERROR;
         $jobLog->isProcessed = true;
         $jobLog->message = 'A test message.';
         $saved = $jobLog->save();
         if (!$saved) {
             throw new FailedToSaveModelException();
         }
     }
 }
 /**
  * Attempts to detect if outbound email settings are setup correctly.
  */
 protected function outboundEmailSettingsAreNotCorrect()
 {
     $testOutboundEmailJobLogs = JobLog::getByType('TestOutboundEmail', 1, 'startdatetime desc');
     if (count($testOutboundEmailJobLogs) == 0) {
         return false;
     }
     if ($testOutboundEmailJobLogs[0]->status == JobLog::STATUS_COMPLETE_WITH_ERROR) {
         return true;
     }
     return false;
 }
 public function testRenderStatusAndMessageListContent()
 {
     $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
     $jobLog = new JobLog();
     $jobLog->isProcessed = true;
     $jobLog->type = 'Monitor';
     $jobLog->startDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time());
     $jobLog->endDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time());
     $jobLog->status = JobLog::STATUS_COMPLETE_WITHOUT_ERROR;
     $this->assertTrue($jobLog->save());
     $this->setGetArray(array('type' => 'Monitor'));
     $content = $this->runControllerWithNoExceptionsAndGetContent('jobsManager/default/jobLogsModalList');
     $this->assertTrue(stripos($content, Zurmo::t('Core', 'Completed')) !== false);
     $jobLog->status = JobLog::STATUS_COMPLETE_WITH_ERROR;
     $this->assertTrue($jobLog->save());
     $this->setGetArray(array('type' => 'Monitor'));
     $content = $this->runControllerWithNoExceptionsAndGetContent('jobsManager/default/jobLogsModalList');
     $this->assertTrue(stripos($content, Zurmo::t('JobsManagerModule', 'Completed with Errors')) !== false);
     $jobLog->status = null;
     $this->assertFalse($jobLog->save());
 }
 protected function preFilter($filterChain)
 {
     if (isset($_POST['ajax'])) {
         return true;
     }
     $queueJobLogs = JobLog::getByType('AutoresponderQueueMessagesInOutbox', 1);
     $processJobLogs = JobLog::getByType('ProcessOutboundEmail', 1);
     if (count($queueJobLogs) == 0 || count($processJobLogs) == 0) {
         Yii::app()->user->setFlash('notification', Zurmo::t('AutorespondersModule', 'Autoresponders will not run properly until scheduled jobs are set up. Contact your administrator.'));
     }
     return true;
 }
 protected function preFilter($filterChain)
 {
     if (isset($_POST['ajax'])) {
         return true;
     }
     $generateJobLogs = JobLog::getByType('CampaignGenerateDueCampaignItems', 1);
     $markJobLogs = JobLog::getByType('CampaignMarkCompleted', 1);
     $queueJobLogs = JobLog::getByType('CampaignQueueMessagesInOutbox', 1);
     $processJobLogs = JobLog::getByType('ProcessOutboundEmail', 1);
     if (count($generateJobLogs) == 0 || count($markJobLogs) == 0 || count($queueJobLogs) == 0 || count($processJobLogs) == 0) {
         Yii::app()->user->setFlash('notification', Zurmo::t('CampaignsModule', 'Campaigns will not run properly until scheduled jobs are set up. Contact your administrator.'));
     }
     return true;
 }
Пример #8
0
 public function testJobLog()
 {
     Yii::app()->user->userModel = User::getByUsername('super');
     $jobLog = new JobLog();
     $jobLog->type = 'Monitor';
     $jobLog->startDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time());
     $jobLog->endDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time());
     $jobLog->status = JobLog::STATUS_COMPLETE_WITHOUT_ERROR;
     //Should fail to save because isProcessed is not specified.
     $this->assertFalse($jobLog->save());
     $jobLog->isProcessed = false;
     $this->assertTrue($jobLog->save());
     $id = $jobLog->id;
     $jobLog = JobLog::getById($id);
     $jobLog->delete();
     $this->assertEquals(0, count(JobInProcess::getAll()));
 }
Пример #9
0
 protected static function getNonMonitorJobLogsUnprocessedWithErrors()
 {
     $searchAttributeData = array();
     $searchAttributeData['clauses'] = array(1 => array('attributeName' => 'type', 'operatorType' => 'doesNotEqual', 'value' => 'Monitor'), 2 => array('attributeName' => 'isProcessed', 'operatorType' => 'doesNotEqual', 'value' => (bool) 1), 3 => array('attributeName' => 'status', 'operatorType' => 'equals', 'value' => JobLog::STATUS_COMPLETE_WITH_ERROR));
     $searchAttributeData['structure'] = '1 and 2 and 3';
     $joinTablesAdapter = new RedBeanModelJoinTablesQueryAdapter('JobLog');
     $where = RedBeanModelDataProvider::makeWhere('JobLog', $searchAttributeData, $joinTablesAdapter);
     return JobLog::getSubset($joinTablesAdapter, null, self::$pageSize, $where, null);
 }
 protected static function getLastCompletedJobLogByType($type)
 {
     assert('is_string($type) && $type != ""');
     $searchAttributeData = array();
     $searchAttributeData['clauses'] = array(1 => array('attributeName' => 'type', 'operatorType' => 'equals', 'value' => $type));
     $searchAttributeData['structure'] = '1';
     $joinTablesAdapter = new RedBeanModelJoinTablesQueryAdapter('JobLog');
     $sort = RedBeanModelDataProvider::resolveSortAttributeColumnName('JobLog', $joinTablesAdapter, 'createdDateTime');
     $where = RedBeanModelDataProvider::makeWhere('JobLog', $searchAttributeData, $joinTablesAdapter);
     $models = JobLog::getSubset($joinTablesAdapter, null, 1, $where, $sort . ' desc');
     if (count($models) > 1) {
         throw new NotSupportedException();
     }
     if (count($models) == 0) {
         return null;
     }
     return $models[0];
 }
Пример #11
0
 public function actionJobLogDetails($id)
 {
     $jobLog = JobLog::getById(intval($id));
     $detailsView = new JobLogDetailsView($this->getId(), $this->getModule()->getId(), $jobLog, strval($jobLog));
     $view = new JobsManagerPageView(ZurmoDefaultAdminViewUtil::makeStandardViewForCurrentUser($this, $detailsView));
     echo $view->render();
 }
 /**
  * @depends testFlashMessageShowsUpIfJobsDidntRun
  */
 public function testFlashMessageDoesNotShowUpIfJobsHaveRun()
 {
     $jobLog = new JobLog();
     $jobLog->type = 'AutoresponderQueueMessagesInOutbox';
     $jobLog->startDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time());
     $jobLog->endDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time());
     $jobLog->status = JobLog::STATUS_COMPLETE_WITHOUT_ERROR;
     $jobLog->isProcessed = false;
     $this->assertTrue($jobLog->save());
     $jobLog = new JobLog();
     $jobLog->type = 'ProcessOutboundEmail';
     $jobLog->startDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time());
     $jobLog->endDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time());
     $jobLog->status = JobLog::STATUS_COMPLETE_WITHOUT_ERROR;
     $jobLog->isProcessed = false;
     $this->assertTrue($jobLog->save());
     $redirectUrl = 'http://www.zurmo.com/';
     $this->setGetArray(array('marketingListId' => static::$marketingListId, 'redirectUrl' => $redirectUrl));
     $content = $this->runControllerWithNoExceptionsAndGetContent('autoresponders/default/create');
     $compareContent = 'Autoresponders will not run properly until scheduled jobs are set up. Contact your administrator.';
     $this->assertNotContains($compareContent, $content);
 }
 /**
  * Given a 'type' of job, run the job.  This is for non-monitor jobs only.
  * @param $type
  * @param MessageLogger $messageLogger
  * @param $isJobInProgress
  * @throws FailedToSaveModelException
  */
 public static function runNonMonitorJob($type, MessageLogger $messageLogger, &$isJobInProgress)
 {
     assert('is_string($type) && $type != "Monitor"');
     assert('is_bool($isJobInProgress)');
     try {
         JobInProcess::getByType($type);
         $messageLogger->addInfoMessage("Existing job detected");
         $isJobInProgress = true;
     } catch (NotFoundException $e) {
         $jobInProcess = new JobInProcess();
         $jobInProcess->type = $type;
         $jobInProcess->save();
         $startDateTime = $jobInProcess->createdDateTime;
         $jobClassName = $type . 'Job';
         $job = new $jobClassName();
         $job->setMessageLogger($messageLogger);
         $ranSuccessfully = $job->run();
         $errorMessage = $job->getErrorMessage();
         $jobInProcess->delete();
         $jobLog = new JobLog();
         $jobLog->type = $type;
         $jobLog->startDateTime = $startDateTime;
         $jobLog->endDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time());
         if ($ranSuccessfully) {
             $messageLogger->addInfoMessage("Job completed successfully");
             $jobLog->status = JobLog::STATUS_COMPLETE_WITHOUT_ERROR;
         } else {
             $messageLogger->addInfoMessage("Job completed with errors");
             $jobLog->status = JobLog::STATUS_COMPLETE_WITH_ERROR;
             $jobLog->message = $errorMessage;
         }
         $jobLog->isProcessed = false;
         if (!$jobLog->save()) {
             throw new FailedToSaveModelException();
         }
         $stuckJob = StuckJob::getByType($type);
         $stuckJob->quantity = 0;
         if (!$stuckJob->save()) {
             throw new FailedToSaveModelException();
         }
     }
 }
 public function testRunMonitorJob()
 {
     Yii::app()->user->userModel = User::getByUsername('super');
     foreach (JobLog::getAll() as $jobLog) {
         $jobLog->delete();
     }
     $isJobInProgress = false;
     JobsManagerUtil::runNonMonitorJob('Test', new MessageLogger(), $isJobInProgress);
     $this->assertFalse($isJobInProgress);
     $jobLogs = JobLog::getAll();
     $this->assertEquals(1, count($jobLogs));
     $this->assertEquals(0, $jobLogs[0]->isProcessed);
     $jobLogId = $jobLogs[0]->id;
     $jobLogs[0]->forget();
     //to ensure cache is cleared before running monitor job
     $isJobInProgress = false;
     JobsManagerUtil::runMonitorJob(new MessageLogger(), $isJobInProgress);
     $this->assertFalse($isJobInProgress);
     $jobLogs = JobLog::getAll();
     $this->assertEquals(2, count($jobLogs));
     $this->assertEquals($jobLogId, $jobLogs[0]->id);
     $this->assertEquals(1, $jobLogs[0]->isProcessed);
     $this->assertEquals(0, $jobLogs[1]->isProcessed);
 }
 /**
  * @depends testSuperUserAllDefaultControllerActions
  */
 public function testWhenJobsHaveRunTheFlashMessageDoesNotShowUp()
 {
     $jobLog = new JobLog();
     $jobLog->type = 'CampaignGenerateDueCampaignItems';
     $jobLog->startDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time());
     $jobLog->endDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time());
     $jobLog->status = JobLog::STATUS_COMPLETE_WITHOUT_ERROR;
     $jobLog->isProcessed = false;
     $this->assertTrue($jobLog->save());
     $jobLog = new JobLog();
     $jobLog->type = 'CampaignMarkCompleted';
     $jobLog->startDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time());
     $jobLog->endDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time());
     $jobLog->status = JobLog::STATUS_COMPLETE_WITHOUT_ERROR;
     $jobLog->isProcessed = false;
     $this->assertTrue($jobLog->save());
     $jobLog = new JobLog();
     $jobLog->type = 'CampaignQueueMessagesInOutbox';
     $jobLog->startDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time());
     $jobLog->endDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time());
     $jobLog->status = JobLog::STATUS_COMPLETE_WITHOUT_ERROR;
     $jobLog->isProcessed = false;
     $this->assertTrue($jobLog->save());
     $jobLog = new JobLog();
     $jobLog->type = 'ProcessOutboundEmail';
     $jobLog->startDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time());
     $jobLog->endDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time());
     $jobLog->status = JobLog::STATUS_COMPLETE_WITHOUT_ERROR;
     $jobLog->isProcessed = false;
     $this->assertTrue($jobLog->save());
     $content = $this->runControllerWithNoExceptionsAndGetContent('campaigns/default/create');
     $compareContent = 'Campaigns will not run properly until scheduled jobs are set up. Contact your administrator.';
     $this->assertNotContains($compareContent, $content);
 }