private async Task FailSubtaskAsync(SubtaskInProgress failedSubtaskInProgress) { var failedSubtask = await _dbContext.Subtasks.FindAsync(failedSubtaskInProgress.SubtaskId); failedSubtask.Status = SubtaskStatus.Error; failedSubtask.Errors = failedSubtaskInProgress.Errors; _subtasksInProgressCleanupService.RemoveSubtasksInProgress(failedSubtask.Id); await FailDistributedTask(failedSubtask); }
public async Task <IActionResult> AssignNextAsync([FromBody] AssignNextSubtaskDTO body) { if (!Guid.TryParse(body.DistributedNodeId, out var distributedNodeId)) { return(BadRequest()); // TODO: specify the reason } var distributedNode = await _distributedNodeResourceService.GetAsync(distributedNodeId); if (distributedNode == null) { return(NotFound()); // TODO: specify the reason } var nextSubtask = await _getNextSubtaskToComputeService.GetNextSubtaskAsync(); if (nextSubtask == null) { return(NotFound()); // TODO: specify the reason } var subtaskInProgress = new SubtaskInProgress { Node = distributedNode, Status = SubtaskInProgressStatus.Executing, Subtask = nextSubtask }; var createdSubtaskInProgress = await _subtaskInProgressResourceService.CreateAsync(subtaskInProgress); nextSubtask.Status = SubtaskStatus.Executing; _dbContext.Subtasks.Update(nextSubtask); await _dbContext.SaveChangesAsync(); var distributedTaskDefinition = await GetSubtasksDistributedTaskDefinition(nextSubtask); var response = new AssignNextSubtaskResultDTO() { CompiledTaskDefinitionURL = _pathsProvider.GetCompiledTaskDefinitionWebPath(distributedTaskDefinition.DefinitionGuid), SubtaskId = nextSubtask.StringId, ProblemPluginInfo = distributedTaskDefinition.ProblemPluginInfo, SubtaskInProgressId = createdSubtaskInProgress.StringId }; return(Created($"/subtasks-in-progress/{createdSubtaskInProgress.Id}", response)); }
private bool IsFinishableSubtaskInProgress(SubtaskInProgress subtaskInProgress, Guid distributedNodeId) { return(subtaskInProgress != null && subtaskInProgress.Status == SubtaskInProgressStatus.Executing && subtaskInProgress.NodeId == distributedNodeId); }