예제 #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;
 }
예제 #2
0
 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;
 }
예제 #3
0
 public function testIsJobInProcessOverThreashold()
 {
     Yii::app()->user->userModel = User::getByUsername('super');
     $jobInProcess = new JobInProcess();
     $jobInProcess->type = 'Test';
     $this->assertTrue($jobInProcess->save());
     //Set the createdDateTime as way in the past, so that it is over the threshold
     $sql = "update " . Item::getTableName('Item') . " set createddatetime = '1980-06-03 18:33:03' where id = " . $jobInProcess->getClassId('Item');
     R::exec($sql);
     $jobInProcessId = $jobInProcess->id;
     $jobInProcess->forget();
     $jobInProcess = JobInProcess::getById($jobInProcessId);
     $this->assertTrue(JobsManagerUtil::isJobInProcessOverThreshold($jobInProcess, $jobInProcess->type));
     $jobInProcess->delete();
     //Test when a job is not over the threshold.
     $jobInProcess = new JobInProcess();
     $jobInProcess->type = 'Test';
     $this->assertTrue($jobInProcess->save());
     $this->assertFalse(JobsManagerUtil::isJobInProcessOverThreshold($jobInProcess, $jobInProcess->type));
     $jobInProcess->delete();
 }
 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;
     }
 }