public function run()
 {
     //Do not run this job if ReadPermissionSubscriptionUpdateComplete is already running
     try {
         JobInProcess::getByType('ReadPermissionSubscriptionComprehensiveUpdate');
     } catch (NotFoundException $e) {
         ReadPermissionsSubscriptionUtil::updateAllReadSubscriptionTables(true);
     }
     return true;
 }
示例#2
0
 public function actionResetJob($type)
 {
     assert('is_string($type) && $type != ""');
     $jobClassName = $type . 'Job';
     try {
         $jobInProcess = JobInProcess::getByType($type);
         $jobInProcess->delete();
         $messageBoxContent = HtmlNotifyUtil::renderHighlightBoxByMessage(Zurmo::t('JobsManagerModule', 'The job {jobName} has been reset.', array('{jobName}' => $jobClassName::getDisplayName())));
         $this->processListAction($messageBoxContent);
     } catch (NotFoundException $e) {
         $messageBoxContent = HtmlNotifyUtil::renderHighlightBoxByMessage(Zurmo::t('JobsManagerModule', 'The job {jobName} was not found to be stuck and therefore was not reset.', array('{jobName}' => $jobClassName::getDisplayName())));
         $this->processListAction($messageBoxContent);
     }
 }
 public function run()
 {
     $counter = 0;
     try {
         while (JobInProcess::getByType('ReadPermissionSubscriptionQuickUpdate') instanceof RedBeanModel && $counter <= self::MAX_NUMBER_OF_TRIES) {
             sleep(30);
             $counter++;
         }
     } catch (NotFoundException $e) {
         ReadPermissionsSubscriptionUtil::updateAllReadSubscriptionTables(false);
         return true;
     }
     return false;
 }
示例#4
0
 public function testJobInProcess()
 {
     Yii::app()->user->userModel = User::getByUsername('super');
     $jobInProcess = new JobInProcess();
     $jobInProcess->type = 'Monitor';
     $this->assertTrue($jobInProcess->save());
     $id = $jobInProcess->id;
     try {
         $jobInProcess = JobInProcess::getByType('SomethingElse');
         $this->fail();
     } catch (NotFoundException $e) {
         //nothing. passes.
     }
     $jobInProcess = JobInProcess::getByType('Monitor');
     $this->assertEquals(1, count($jobInProcess));
     $this->assertEquals($id, $jobInProcess->id);
     $jobInProcess->delete();
     $this->assertEquals(0, count(JobInProcess::getAll()));
 }
 protected static function getIfJobIsInProcessOtherwiseReturnNullByType($type)
 {
     assert('is_string($type) && $type != ""');
     try {
         $jobInProcess = JobInProcess::getByType($type);
     } catch (NotFoundException $e) {
         $jobInProcess = null;
     }
     return $jobInProcess;
 }
 /**
  * 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();
         }
     }
 }
 /**
  * Execute the action
  * @param array $args - command line parameters specific for this command
  * @return int|void
  */
 public function run($args)
 {
     if (!isset($args[0])) {
         $this->usageError('A username must be specified.');
     }
     try {
         Yii::app()->user->userModel = User::getByUsername($args[0]);
     } catch (NotFoundException $e) {
         $this->usageError('The specified username does not exist.');
     }
     $group = Group::getByName(Group::SUPER_ADMINISTRATORS_GROUP_NAME);
     if (!$group->users->contains(Yii::app()->user->userModel)) {
         $this->usageError('The specified user is not a super administrator.');
     }
     if (!isset($args[1])) {
         $this->usageError('JobType must be provided and must be existing jobType!');
     } else {
         $jobType = $args[1];
     }
     $template = "{message}\n";
     $messageStreamer = new MessageStreamer($template);
     $messageStreamer->setExtraRenderBytes(0);
     $messageStreamer->add('');
     if ($jobType == 'All') {
         $messageStreamer->add("Reset all jobs.");
         $jobsInProcess = JobInProcess::getAll();
         if (is_array($jobsInProcess) && count($jobsInProcess) > 0) {
             foreach ($jobsInProcess as $jobInProcess) {
                 $jobInProcess->delete();
                 $messageStreamer->add("The job {$jobInProcess->type} has been reset.");
             }
         } else {
             $messageStreamer->add("There are no jobs in process to be reset.");
         }
     } else {
         $jobClassName = $jobType . 'Job';
         if (!@class_exists($jobClassName)) {
             $messageStreamer->add("Error! The {$jobClassName} does not exist.");
         } else {
             try {
                 $jobInProcess = JobInProcess::getByType($jobType);
                 $jobInProcess->delete();
                 $messageStreamer->add("The job {$jobClassName} has been reset.");
             } catch (NotFoundException $e) {
                 $messageStreamer->add("The job {$jobClassName} was not found to be stuck and therefore was not reset.");
             }
         }
     }
 }