private async Task <TaskExecutionStartResponse> TryGetExecutionTokenAsync(TaskId taskId, int taskDefinitionId, int taskExecutionId, int concurrencyLimit)
        {
            var tokenRequest = new TokenRequest()
            {
                TaskId           = taskId,
                TaskDefinitionId = taskDefinitionId,
                TaskExecutionId  = taskExecutionId.ToString(),
                ConcurrencyLimit = concurrencyLimit
            };

            try
            {
                var tokenResponse = await _executionTokenRepository.TryAcquireExecutionTokenAsync(tokenRequest).ConfigureAwait(false);

                var response = new TaskExecutionStartResponse();
                response.ExecutionTokenId = tokenResponse.ExecutionTokenId;
                response.GrantStatus      = tokenResponse.GrantStatus;
                response.StartedAt        = tokenResponse.StartedAt;
                response.TaskExecutionId  = taskExecutionId.ToString();

                return(response);
            }
            catch (Exception ex)
            {
                var response = new TaskExecutionStartResponse();
                response.StartedAt        = DateTime.UtcNow;
                response.GrantStatus      = GrantStatus.Denied;
                response.ExecutionTokenId = "0";
                response.TaskExecutionId  = taskExecutionId.ToString();
                response.Ex = ex;

                return(response);
            }
        }
        private TaskExecutionStartResponse TryGetExecutionToken(TaskId taskId, int taskDefinitionId, int taskExecutionId, int concurrencyLimit)
        {
            var tokenRequest = new TokenRequest()
            {
                TaskId           = taskId,
                TaskDefinitionId = taskDefinitionId,
                TaskExecutionId  = taskExecutionId.ToString(),
                ConcurrencyLimit = concurrencyLimit
            };

            var tokenResponse = _executionTokenRepository.TryAcquireExecutionToken(tokenRequest);

            var response = new TaskExecutionStartResponse();

            response.ExecutionTokenId = tokenResponse.ExecutionTokenId;
            response.GrantStatus      = tokenResponse.GrantStatus;
            response.StartedAt        = tokenResponse.StartedAt;
            response.TaskExecutionId  = taskExecutionId.ToString();

            return(response);
        }