CBPWorkflow::RunQueuedItem: Bitrix method

      
<?php 
//  CBPWorkflow :: RunQueuedItem()
//  /dist/bitrix/modules/bizproc/classes/general/workflow.php:455

    
private function RunQueuedItem(CBPActivity $activity$activityOperationException $exception null)
    {
        
/** @var $trackingService CBPTrackingService */
        
if ($activityOperation == CBPActivityExecutorOperationType::Execute)
        {
            if (
$activity->executionStatus == CBPActivityExecutionStatus::Executing)
            {
                try
                {
                    
$trackingService $this->GetService("TrackingService");
                    
$trackingService->Write($this->GetInstanceId(), CBPTrackingType::ExecuteActivity$activity->GetName(), $activity->executionStatus$activity->executionResult, ($activity->IsPropertyExists("Title") ? $activity->Title ""), "");
                    
$newStatus $activity->Execute();

                    
//analyse robots - Temporary, it is prototype
                    
if ($trackingService->isForcedMode($this->GetInstanceId()))
                    {
                        
$activityType substr(get_class($activity), 3);
                        if (!
in_array($activityType, [
                            
'SequentialWorkflowActivity',
                            
'ParallelActivity',
                            
'SequenceActivity',
                            
'DelayActivity',
                            
'IfElseActivity',
                            
'IfElseBranchActivity'
                        
]))
                        {
                            
/** @var \Bitrix\Bizproc\Service\Analytics $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;
                }
            }
        }
    }