/** * @see BaseJob::run() */ public function run() { try { $originalUser = Yii::app()->user->userModel; Yii::app()->user->userModel = BaseControlUserConfigUtil::getUserToRunAs(); foreach (ByTimeWorkflowInQueue::getModelsToProcess(self::$pageSize) as $byTimeWorkflowInQueue) { try { $model = $this->resolveModel($byTimeWorkflowInQueue); $this->resolveSavedWorkflowIsValid($byTimeWorkflowInQueue); $this->processByTimeWorkflowInQueue($byTimeWorkflowInQueue, $model); } catch (NotFoundException $e) { WorkflowUtil::handleProcessingException($e, 'application.modules.workflows.jobs.ByTimeWorkflowInQueueJob.run'); } $byTimeWorkflowInQueue->delete(); } Yii::app()->user->userModel = $originalUser; return true; } catch (MissingASuperAdministratorException $e) { //skip running workflow, since no super administrators are available. $this->errorMessage = Zurmo::t('WorkflowsModule', 'Could not process since no super administrators were found'); return false; } }
/** * @see BaseJob::run() */ public function run() { try { $originalUser = Yii::app()->user->userModel; Yii::app()->user->userModel = BaseControlUserConfigUtil::getUserToRunAs(); $processedModelsCount = 0; $batchSize = $this->resolveBatchSize(); if ($batchSize != null) { $resolvedBatchSize = $batchSize + 1; } else { $resolvedBatchSize = null; } foreach (ByTimeWorkflowInQueue::getModelsToProcess($resolvedBatchSize) as $byTimeWorkflowInQueue) { if ($processedModelsCount < $batchSize || $batchSize == null) { try { $model = $this->resolveModel($byTimeWorkflowInQueue); $this->resolveSavedWorkflowIsValid($byTimeWorkflowInQueue); $this->processByTimeWorkflowInQueue($byTimeWorkflowInQueue, $model); } catch (NotFoundException $e) { WorkflowUtil::handleProcessingException($e, 'application.modules.workflows.jobs.ByTimeWorkflowInQueueJob.run'); } $byTimeWorkflowInQueue->delete(); $processedModelsCount++; } else { Yii::app()->jobQueue->add('ByTimeWorkflowInQueue', 5); break; } } Yii::app()->user->userModel = $originalUser; return true; } catch (MissingASuperAdministratorException $e) { //skip running workflow, since no super administrators are available. $this->errorMessage = Zurmo::t('WorkflowsModule', 'Could not process since no super administrators were found'); return false; } }
/** * @depends testResolveByWorkflowIdAndModel */ public function testGetModelsToProcess($pageSize) { $this->assertEquals(1, ByTimeWorkflowInQueue::getCount()); $models = ByTimeWorkflowInQueue::getModelsToProcess(10); $this->assertEquals(1, count($models)); //Now have one that is not ready for processing. It should still only get 1 $model = new WorkflowModelTestItem(); $model->lastName = 'Green2'; $model->string = 'string2'; $saved = $model->save(); $this->assertTrue($saved); $savedWorkflows = SavedWorkflow::getByName('some workflow2'); $byTimeWorkflowInQueue = new ByTimeWorkflowInQueue(); $byTimeWorkflowInQueue->modelClassName = get_class($model); $byTimeWorkflowInQueue->modelItem = $model; $byTimeWorkflowInQueue->processDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time() + 86400); $byTimeWorkflowInQueue->savedWorkflow = $savedWorkflows[0]; $saved = $byTimeWorkflowInQueue->save(); $this->assertTrue($saved); $models = ByTimeWorkflowInQueue::getModelsToProcess(10); $this->assertEquals(1, count($models)); }