public TaskExecutionStartResponse Start(TaskExecutionStartRequest startRequest)
        {
            ValidateStartRequest(startRequest);
            var taskDefinition = _taskRepository.EnsureTaskDefinition(startRequest.TaskId);

            if (startRequest.TaskDeathMode == TaskDeathMode.KeepAlive)
                return StartKeepAliveExecution(startRequest, taskDefinition.TaskDefinitionId);

            if (startRequest.TaskDeathMode == TaskDeathMode.Override)
                return StartOverrideExecution(startRequest, taskDefinition.TaskDefinitionId);

            throw new ExecutionException("Unsupported TaskDeathMode");
        }
        private TaskExecutionStartResponse StartOverrideExecution(TaskExecutionStartRequest startRequest, int taskDefinitionId)
        {
            var taskExecutionId = CreateOverrideTaskExecution(startRequest.TaskId, taskDefinitionId, startRequest.OverrideThreshold.Value, startRequest.ReferenceValue,
                startRequest.FailedTaskRetryLimit, startRequest.DeadTaskRetryLimit, startRequest.TasklingVersion, startRequest.TaskExecutionHeader);
            RegisterEvent(startRequest.TaskId, taskExecutionId.ToString(), EventType.Start, null);

            var tokenResponse = TryGetExecutionToken(startRequest.TaskId, taskDefinitionId, taskExecutionId, startRequest.ConcurrencyLimit);

            if (tokenResponse.GrantStatus == GrantStatus.Denied)
            {
                SetBlockedOnTaskExecution(startRequest.TaskId, taskExecutionId.ToString());
                RegisterEvent(startRequest.TaskId, taskExecutionId.ToString(), EventType.Blocked, null);
            }

            return tokenResponse;
        }
        private void ValidateStartRequest(TaskExecutionStartRequest startRequest)
        {
            if (startRequest.TaskDeathMode == TaskDeathMode.KeepAlive)
            {
                if (!startRequest.KeepAliveInterval.HasValue)
                    throw new ExecutionArgumentsException("KeepAliveInterval must be set when using KeepAlive mode");

                if (!startRequest.KeepAliveDeathThreshold.HasValue)
                    throw new ExecutionArgumentsException("KeepAliveDeathThreshold must be set when using KeepAlive mode");
            }
            else if (startRequest.TaskDeathMode == TaskDeathMode.Override)
            {
                if (!startRequest.OverrideThreshold.HasValue)
                    throw new ExecutionArgumentsException("OverrideThreshold must be set when using Override mode");
            }
        }