text: ﻿CREATE PROCEDURE [procfwk].[SetLogActivityFailed]
  	(
  	@ExecutionId UNIQUEIDENTIFIER,
  	@StageId INT,
  	@PipelineId INT,
  	@CallingActivity VARCHAR(255)
  	)
  AS
  
  BEGIN
  	SET NOCOUNT ON;
  	
  	--mark specific failure pipeline
  	UPDATE
  		[procfwk].[CurrentExecution]
  	SET
  		[PipelineStatus] = @CallingActivity + 'Error'
  	WHERE
  		[LocalExecutionId] = @ExecutionId
  		AND [StageId] = @StageId
  		AND [PipelineId] = @PipelineId
  
  	--persist failed pipeline records to long term log
  	INSERT INTO [procfwk].[ExecutionLog]
  		(
  		[LocalExecutionId],
  		[StageId],
  		[PipelineId],
  		[CallingDataFactoryName],
  		[ResourceGroupName],
  		[DataFactoryName],
  		[PipelineName],
  		[StartDateTime],
  		[PipelineStatus],
  		[EndDateTime],
  		[AdfPipelineRunId],
  		[PipelineParamsUsed]
  		)
  	SELECT
  		[LocalExecutionId],
  		[StageId],
  		[PipelineId],
  		[CallingDataFactoryName],
  		[ResourceGroupName],
  		[DataFactoryName],
  		[PipelineName],
  		[StartDateTime],
  		[PipelineStatus],
  		[EndDateTime],
  		[AdfPipelineRunId],
  		[PipelineParamsUsed]
  	FROM
  		[procfwk].[CurrentExecution]
  	WHERE
  		[PipelineStatus] = @CallingActivity + 'Error'
  		AND [StageId] = @StageId
  		AND [PipelineId] = @PipelineId
  	
  	--decide how to proceed with error/failure depending on framework property configuration
  	IF ([procfwk].[GetPropertyValueInternal]('FailureHandling')) = 'None'
  		BEGIN
  			--do nothing allow processing to carry on regardless
  			RETURN 0;
  		END;
  		
  	ELSE IF ([procfwk].[GetPropertyValueInternal]('FailureHandling')) = 'Simple'
  		BEGIN
  			--flag all downstream stages as blocked
  			UPDATE
  				[procfwk].[CurrentExecution]
  			SET
  				[PipelineStatus] = 'Blocked',
  				[IsBlocked] = 1
  			WHERE
  				[LocalExecutionId] = @ExecutionId
  				AND [StageId] > @StageId;
  		END;
  	
  	ELSE IF ([procfwk].[GetPropertyValueInternal]('FailureHandling')) = 'DependencyChain'
  		BEGIN
  			EXEC [procfwk].[SetExecutionBlockDependants]
  				@ExecutionId = @ExecutionId,
  				@PipelineId = @PipelineId
  		END;
  	ELSE
  		BEGIN
  			RAISERROR('Unknown failure handling state.',16,1);
  			RETURN 0;
  		END;
  END;