private async Task <TaskExecutionStartResponse> StartOverrideExecutionAsync(TaskExecutionStartRequest startRequest, int taskDefinitionId) { var taskExecutionId = await CreateOverrideTaskExecutionAsync(startRequest.TaskId, taskDefinitionId, startRequest.OverrideThreshold.Value, startRequest.ReferenceValue, startRequest.FailedTaskRetryLimit, startRequest.DeadTaskRetryLimit, startRequest.TasklingVersion, startRequest.TaskExecutionHeader).ConfigureAwait(false); await RegisterEventAsync(startRequest.TaskId, taskExecutionId.ToString(), EventType.Start, null).ConfigureAwait(false); var tokenResponse = await TryGetExecutionTokenAsync(startRequest.TaskId, taskDefinitionId, taskExecutionId, startRequest.ConcurrencyLimit).ConfigureAwait(false); if (tokenResponse.GrantStatus == GrantStatus.Denied) { await SetBlockedOnTaskExecutionAsync(startRequest.TaskId, taskExecutionId.ToString()).ConfigureAwait(false); if (tokenResponse.Ex == null) { await RegisterEventAsync(startRequest.TaskId, taskExecutionId.ToString(), EventType.Blocked, null).ConfigureAwait(false); } else { await RegisterEventAsync(startRequest.TaskId, taskExecutionId.ToString(), EventType.Blocked, tokenResponse.Ex.ToString()).ConfigureAwait(false); } } return(tokenResponse); }
private void SerializeHeaderIfExists(TaskExecutionStartRequest startRequest) { if (_taskExecutionHeader != null) { startRequest.TaskExecutionHeader = JsonGenericSerializer.Serialize(_taskExecutionHeader); } }
private void SetStartRequestValues(TaskExecutionStartRequest startRequest, string referenceValue) { if (_taskExecutionOptions.TaskDeathMode == TaskDeathMode.KeepAlive) { if (!_taskExecutionOptions.KeepAliveInterval.HasValue) { throw new ExecutionArgumentsException("KeepAliveInterval must be set when using KeepAlive mode"); } if (!_taskExecutionOptions.KeepAliveDeathThreshold.HasValue) { throw new ExecutionArgumentsException("KeepAliveDeathThreshold must be set when using KeepAlive mode"); } startRequest.KeepAliveDeathThreshold = _taskExecutionOptions.KeepAliveDeathThreshold; startRequest.KeepAliveInterval = _taskExecutionOptions.KeepAliveInterval; } if (_taskExecutionOptions.TaskDeathMode == TaskDeathMode.Override) { if (!_taskExecutionOptions.OverrideThreshold.HasValue) { throw new ExecutionArgumentsException("OverrideThreshold must be set when using KeepAlive mode"); } startRequest.OverrideThreshold = _taskExecutionOptions.OverrideThreshold.Value; } startRequest.ReferenceValue = referenceValue; }
private void SetStartRequestTasklingVersion(TaskExecutionStartRequest startRequest) { Assembly assembly = Assembly.GetExecutingAssembly(); FileVersionInfo fileVersionInfo = FileVersionInfo.GetVersionInfo(assembly.Location); string version = fileVersionInfo.ProductVersion; startRequest.TasklingVersion = version; }
private TaskExecutionStartRequest CreateStartRequest(string referenceValue) { var startRequest = new TaskExecutionStartRequest(new TaskId(_taskExecutionInstance.ApplicationName, _taskExecutionInstance.TaskName), _taskExecutionOptions.TaskDeathMode, _taskExecutionOptions.ConcurrencyLimit, _taskConfiguration.FailedTaskRetryLimit, _taskConfiguration.DeadTaskRetryLimit); SetStartRequestValues(startRequest, referenceValue); SetStartRequestTasklingVersion(startRequest); SerializeHeaderIfExists(startRequest); return(startRequest); }
public async Task <TaskExecutionStartResponse> StartAsync(TaskExecutionStartRequest startRequest) { ValidateStartRequest(startRequest); var taskDefinition = await _taskRepository.EnsureTaskDefinitionAsync(startRequest.TaskId).ConfigureAwait(false); if (startRequest.TaskDeathMode == TaskDeathMode.KeepAlive) { return(await StartKeepAliveExecutionAsync(startRequest, taskDefinition.TaskDefinitionId).ConfigureAwait(false)); } if (startRequest.TaskDeathMode == TaskDeathMode.Override) { return(await StartOverrideExecutionAsync(startRequest, taskDefinition.TaskDefinitionId).ConfigureAwait(false)); } throw new ExecutionException("Unsupported TaskDeathMode"); }
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"); } } }