Beispiel #1
0
 public function run()
 {
     $jobsInProcess = static::getNonMonitorJobsInProcessModels();
     $jobsAreStuck = false;
     $jobTitleLabels = array();
     foreach ($jobsInProcess as $jobInProcess) {
         if (JobsManagerUtil::isJobInProcessOverThreshold($jobInProcess, $jobInProcess->type)) {
             $jobTitleLabels[] = strval($jobInProcess);
             $jobsAreStuck = true;
         }
     }
     if ($jobsAreStuck) {
         self::makeJobStuckNotification($jobTitleLabels);
     }
     $jobLogs = static::getNonMonitorJobLogsUnprocessedWithErrors();
     foreach ($jobLogs as $jobLog) {
         $message = new NotificationMessage();
         $message->htmlContent = Zurmo::t('JobsManagerModule', 'Job completed with errors.');
         $url = Yii::app()->createAbsoluteUrl('jobsManager/default/jobLogDetails/', array('id' => $jobLog->id));
         $message->htmlContent .= "<br/>" . ZurmoHtml::link(Zurmo::t('Core', 'Click Here'), $url);
         $rules = new JobCompletedWithErrorsNotificationRules();
         NotificationsUtil::submit($message, $rules);
         $jobLog->isProcessed = true;
         $jobLog->save();
     }
     $this->updateUnprocessedJobLogsWithoutErrors();
     return true;
 }
 /**
  * @param User $userToSendTo
  * @param MessageLogger $messageLogger
  */
 public function run(User $userToSendTo, $messageLogger)
 {
     MonitorJob::makeJobStuckNotification(array('Process Outbound Email Job', 'Process Inbound Email Job'));
     $messageLogger->addInfoMessage('Sending a job is stuck message');
     JobsManagerUtil::makeMonitorStuckJobNotification();
     $messageLogger->addInfoMessage('Sending monitor job stuck message');
     //Clear out notifications for super user
     $searchAttributeData = array();
     $searchAttributeData['clauses'] = array(1 => array('attributeName' => 'owner', 'relatedAttributeName' => 'id', 'operatorType' => 'equals', 'value' => Yii::app()->user->userModel->id));
     $searchAttributeData['structure'] = '1';
     $joinTablesAdapter = new RedBeanModelJoinTablesQueryAdapter('Notification');
     $where = RedBeanModelDataProvider::makeWhere('Notification', $searchAttributeData, $joinTablesAdapter);
     $models = Notification::getSubset($joinTablesAdapter, null, null, $where, null);
     foreach ($models as $model) {
         $model->delete();
     }
 }
 public function run()
 {
     $jobsInProcess = static::getNonMonitorJobsInProcessModels();
     $jobsAreStuck = false;
     $jobTitleLabels = array();
     $jobsInProcessToReset = array();
     foreach ($jobsInProcess as $jobInProcess) {
         if (JobsManagerUtil::isJobInProcessOverThreshold($jobInProcess, $jobInProcess->type)) {
             $stuckJob = StuckJob::getByType($jobInProcess->type);
             $stuckJob->quantity = $stuckJob->quantity + 1;
             if (!$stuckJob->save()) {
                 throw new FailedToSaveModelException();
             }
             $jobsInProcessToReset[] = $jobInProcess;
             //Only processes once the threshold is reach, not each time after that
             if ($stuckJob->quantity == static::$stuckNotificationThreshold) {
                 $jobTitleLabels[] = strval($jobInProcess);
                 $jobsAreStuck = true;
             }
         }
     }
     if ($jobsAreStuck) {
         self::makeJobStuckNotification($jobTitleLabels);
     }
     foreach ($jobsInProcessToReset as $jobInProcessToReset) {
         $jobInProcessToReset->delete();
     }
     $jobLogs = static::getNonMonitorJobLogsUnprocessedWithErrors();
     foreach ($jobLogs as $jobLog) {
         $message = new NotificationMessage();
         $commonMessage = Zurmo::t('JobsManagerModule', 'Job completed with errors.');
         $message->htmlContent = $commonMessage;
         $url = Yii::app()->createAbsoluteUrl('jobsManager/default/jobLogDetails/', array('id' => $jobLog->id));
         $message->htmlContent .= "<br/>" . ZurmoHtml::link(Zurmo::t('Core', 'Click Here'), $url, array('target' => '_blank'));
         $message->textContent = $commonMessage;
         $message->textContent .= "\n" . Zurmo::t('JobsManagerModule', 'See the job log details in this link: {url}', array('{url}' => ShortUrlUtil::createShortUrl($url)));
         $rules = new JobCompletedWithErrorsNotificationRules();
         NotificationsUtil::submit($message, $rules);
         $jobLog->isProcessed = true;
         $jobLog->save();
     }
     $this->updateUnprocessedJobLogsWithoutErrors();
     return true;
 }
 protected static function resolveStatusByJobInProcess($jobInProcess)
 {
     assert('$jobInProcess instanceof JobInProcess || $jobInProcess == null');
     if ($jobInProcess != null && JobsManagerUtil::isJobInProcessOverThreshold($jobInProcess, $jobInProcess->type)) {
         return self::STATUS_IN_PROCESS_STUCK;
     } elseif ($jobInProcess != null) {
         return self::STATUS_IN_PROCESS;
     } else {
         return self::STATUS_NOT_RUNNING;
     }
 }
 /**
  * Execute the action.  Changes max run time to 5 minutes, pass the optional parameter
  * @param array command line parameters specific for this command
  */
 public function run($args)
 {
     if (!isset($args[0])) {
         $this->usageError('A username must be specified.');
     }
     if (!isset($args[1])) {
         $this->usageError('A job type must be specified.');
     }
     try {
         Yii::app()->user->userModel = User::getByUsername($args[0]);
         $group = Group::getByName(Group::SUPER_ADMINISTRATORS_GROUP_NAME);
         if (!$group->users->contains(Yii::app()->user->userModel)) {
             $this->usageError('The username specified must be for a super administrator.');
         }
     } catch (NotFoundException $e) {
         $this->usageError('The specified username does not exist.');
     }
     if (!is_string($args[1])) {
         $this->usageError('The specified job type to run is invalid.');
     } else {
         $jobClassName = $args[1] . 'Job';
         if (!@class_exists($jobClassName)) {
             $this->usageError('The specified job type to run does not exist.');
         }
     }
     if (isset($args[2])) {
         $timeLimit = (int) $args[2];
     } else {
         $timeLimit = 300;
     }
     if (isset($args[3])) {
         $messageLoggerClassName = $args[3];
     } else {
         $messageLoggerClassName = 'MessageLogger';
     }
     echo "\n";
     $isJobInProgress = false;
     JobsManagerUtil::runFromJobManagerCommandOrBrowser($args[1], $timeLimit, $messageLoggerClassName, $isJobInProgress, false);
 }
 public function actionRunAjaxJob($type, $timeLimit = 500, $messageLoggerClassName = 'MessageLogger')
 {
     Yii::app()->getClientScript()->setToAjaxMode();
     $template = '<li>{message}</li>';
     $isJobInProgress = false;
     try {
         JobsManagerUtil::runFromJobManagerCommandOrBrowser($type, (int) $timeLimit, $messageLoggerClassName, $isJobInProgress, true, $template);
     } catch (Exception $e) {
         echo Zurmo::t('JobsManagerModule', 'There was an error. Please check logs for more details');
     }
     Yii::app()->end(0, false);
 }
 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);
 }
 public function actionRunJob($type, $timeLimit = 500, $messageLoggerClassName = 'MessageLogger')
 {
     if (!Group::isUserASuperAdministrator(Yii::app()->user->userModel)) {
         echo Zurmo::t('JobsManagerModule', 'Only super administrators can run jobs from the browser');
         Yii::app()->end(0, false);
     }
     $breadCrumbLinks = array(Zurmo::t('JobsManagerModule', 'JobsManagerModuleSingularLabel', LabelUtil::getTranslationParamsForAllModules()) => array('/jobsManager/default'), Zurmo::t('JobsManagerModule', 'Run Job'));
     $runJobView = new RunJobView($this->getId(), $this->getModule()->getId(), $type, (int) $timeLimit);
     $view = new JobsManagerPageView(ZurmoDefaultAdminViewUtil::makeViewWithBreadcrumbsForCurrentUser($this, $runJobView, $breadCrumbLinks, 'SettingsBreadCrumbView'));
     echo $view->render();
     $template = ZurmoHtml::script("\$('#logging-table ol').append('<li>{message}</li>');");
     $isJobInProgress = false;
     JobsManagerUtil::runFromJobManagerCommandOrBrowser($type, (int) $timeLimit, $messageLoggerClassName, $isJobInProgress, true, $template);
     echo ZurmoHtml::script('$("#progress-table").hide(); $("#complete-table").show();');
 }
 public function testMakeMonitorStuckJobNotification()
 {
     $super = User::getByUsername('super');
     Yii::app()->user->userModel = $super;
     $super->primaryEmail->emailAddress = '*****@*****.**';
     $this->assertTrue($super->save());
     $notificationInitalCount = Notification::getCount();
     $emailMessageInitialCount = EmailMessage::getCount();
     JobsManagerUtil::makeMonitorStuckJobNotification();
     $notifications = Notification::getAll();
     $emailMessages = EmailMessage::getAll();
     $this->assertCount($emailMessageInitialCount + 1, $notifications);
     $this->assertCount($notificationInitalCount + 1, $emailMessages);
     $this->assertEquals('The monitor job is stuck.', $notifications[0]->notificationMessage->htmlContent);
     $this->assertEquals('The monitor job is stuck.', $notifications[0]->notificationMessage->textContent);
     $this->assertContains('The monitor job is stuck.', $emailMessages[0]->content->htmlContent);
     $this->assertContains('The monitor job is stuck.', $emailMessages[0]->content->textContent);
 }