CBPWorkflow::runQueuedItem

  1. Bitrix24 API (v. 23.675.0)
  2. bizproc
  3. CBPWorkflow
  4. runQueuedItem
  • Модуль: bizproc
  • Путь к файлу: ~/bitrix/modules/bizproc/classes/general/workflow.php
  • Класс: CBPWorkflow
  • Вызов: CBPWorkflow::runQueuedItem
private function runQueuedItem(CBPActivity $activity, $activityOperation, Exception $exception = null)
{
	/** @var $trackingService CBPTrackingService */
	if ($activityOperation == CBPActivityExecutorOperationType::Execute)
	{
		if ($activity->executionStatus == CBPActivityExecutionStatus::Executing)
		{
			try
			{
				$newStatus = CBPActivityExecutionStatus::Closed;
				if ($activity->isActivated())
				{
					$trackingService = $this->getService('TrackingService');
					$trackingService->write(
						$this->getInstanceId(),
						CBPTrackingType::ExecuteActivity,
						$activity->getName(),
						$activity->executionStatus,
						$activity->executionResult,
						$activity->getTitle(),
						''
					);
					$newStatus = $activity->Execute();

					//analyse robots - Temporary, it is prototype
					if ($trackingService->isForcedMode($this->GetInstanceId()))
					{
						$activityType = mb_substr(get_class($activity), 3);
						if (!in_array($activityType, [
							'SequentialWorkflowActivity',
							'ParallelActivity',
							'SequenceActivity',
							'DelayActivity',
							'IfElseActivity',
							'IfElseBranchActivity'
						]))
						{
							/** @var BitrixBizprocServiceAnalytics $analyticsService */
							$analyticsService = $this->GetService("AnalyticsService");
							if ($analyticsService->isEnabled())
							{
								$analyticsService->write(
									$activity->GetDocumentId(),
									'robot_run',
									$activityType
								);
							}
						}
					}
				}

				if ($newStatus == CBPActivityExecutionStatus::Closed)
				{
					$this->CloseActivity($activity);
				}
				elseif ($newStatus != CBPActivityExecutionStatus::Executing)
				{
					throw new Exception('InvalidExecutionStatus');
				}
			}
			catch (Exception $e)
			{
				throw $e;
			}
		}
	}
	elseif ($activityOperation == CBPActivityExecutorOperationType::Cancel)
	{
		if ($activity->executionStatus == CBPActivityExecutionStatus::Canceling)
		{
			try
			{
				$trackingService = $this->GetService("TrackingService");
				$trackingService->Write($this->GetInstanceId(), CBPTrackingType::CancelActivity, $activity->GetName(), $activity->executionStatus, $activity->executionResult, ($activity->IsPropertyExists("Title") ? $activity->Title : ""), "");

				$newStatus = $activity->Cancel();

				if ($newStatus == CBPActivityExecutionStatus::Closed)
					$this->CloseActivity($activity);
				elseif ($newStatus != CBPActivityExecutionStatus::Canceling)
					throw new Exception("InvalidExecutionStatus");
			}
			catch (Exception $e)
			{
				throw $e;
			}
		}
	}
	elseif ($activityOperation == CBPActivityExecutorOperationType::HandleFault)
	{
		if ($activity->executionStatus == CBPActivityExecutionStatus::Faulting)
		{
			try
			{
				$trackingService = $this->GetService("TrackingService");
				$trackingService->Write($this->GetInstanceId(), CBPTrackingType::FaultActivity, $activity->GetName(), $activity->executionStatus, $activity->executionResult, ($activity->IsPropertyExists("Title") ? $activity->Title : ""), ($exception != null ? ($exception->getCode()? "[".$exception->getCode()."] " : '').$exception->getMessage() : ""));

				$newStatus = $activity->HandleFault($exception);

				if ($newStatus == CBPActivityExecutionStatus::Closed)
					$this->CloseActivity($activity);
				elseif ($newStatus != CBPActivityExecutionStatus::Faulting)
					throw new Exception("InvalidExecutionStatus");
			}
			catch (Exception $e)
			{
				throw $e;
			}
		}
	}
}

Добавить комментарий