public async Task <IActionResult> GetAgentRequestStatus([FromBody] AgentRequestStatusItem agentRequestStatusItem) { // Need to know the job correlation id and work item id. // Work item id is the agent id, and job correlation is in the agent data. string workItemId = agentRequestStatusItem.agentId; string correlationId = agentRequestStatusItem.agentData.correlationId; WorkItemDetails workItemDetails; try { _logger.LogTrace($"Looking up work item details for agent {workItemId} in Helix Job {correlationId}"); using (IHelixApi api = GetHelixApi(agentRequestStatusItem.agentData.isPublicQueue)) { workItemDetails = await api.WorkItem.DetailsAsync(correlationId, workItemId); } } catch (Exception e) { _logger.LogError($"Failed to find work item {workItemId} in Helix Job {correlationId}:{Environment.NewLine}{e.ToString()}"); return(BadRequest()); } _logger.LogTrace($"Work item {workItemId} in Helix job {correlationId} is {workItemDetails.State}"); switch (workItemDetails.State.ToLowerInvariant()) { case "running": case "finished": case "passed": return(Json(new AgentStatusItem() { statusMessage = $"Helix work item in job {correlationId} for agent {workItemId} was picked up by machine {workItemDetails.MachineName} and is {workItemDetails.State}" })); case "unscheduled": return(Json(new AgentStatusItem() { statusMessage = $"Helix work item in job {correlationId} for agent {workItemId} is currently {workItemDetails.State} or does not exist." })); case "waiting": return(Json(new AgentStatusItem() { statusMessage = $"Helix work item in job {correlationId} for agent {workItemId} is currently waiting for a machine." })); case "failed": return(Json(new AgentStatusItem() { statusMessage = $"Helix work item in job {correlationId} for agent {workItemId} failed. Please check the logs." })); default: throw new NotImplementedException( $"Got unexpected state '{workItemDetails.State}' for agent {workItemId} in job {correlationId}"); } }
public async Task <IActionResult> GetAgentRequestStatus([FromBody] AgentRequestStatusItem agentRequestStatusItem) { // Need to know the job correlation id and work item id. // Work item id is the agent id, and job correlation is in the agent data. string workItemId = agentRequestStatusItem.agentId; string correlationId = agentRequestStatusItem.agentData?.correlationId; if (string.IsNullOrEmpty(correlationId)) { // This means the call came back before we've provisioned it. We don't have any meaningful // response right now, so return the empty string to reflect "no status". _logger.LogInformation("Status request has no agentData, returning empty status"); return(NoContent()); } WorkItemDetails workItemDetails; try { _logger.LogTrace($"Looking up work item details for agent {workItemId} in Helix Job {correlationId}"); IHelixApi api = GetHelixApi(agentRequestStatusItem.agentData.isPublicQueue); workItemDetails = await api.WorkItem.DetailsAsync(correlationId, workItemId); } catch (Exception e) { _logger.LogError($"Failed to find work item {workItemId} in Helix Job {correlationId}:{Environment.NewLine}{e.ToString()}"); return(BadRequest()); } _logger.LogTrace($"Work item {workItemId} in Helix job {correlationId} is {workItemDetails.State}"); switch (workItemDetails.State.ToLowerInvariant()) { case "running": case "finished": case "passed": return(Json(new AgentStatusItem() { statusMessage = $"Work is in progress or complete. (Helix work item in job {correlationId} for agent {workItemId} was picked up by machine {workItemDetails.MachineName} and is {workItemDetails.State})" })); case "unscheduled": return(Json(new AgentStatusItem() { statusMessage = $"Work has been submitted to the Helix API, but has not started yet (Helix work item in job {correlationId} for agent {workItemId} is currently in state '{workItemDetails.State}')" })); case "waiting": return(Json(new AgentStatusItem() { statusMessage = $"Work has been submitted to the Helix API, and is waiting for a machine (Helix work item in job {correlationId} for agent {workItemId} is currently waiting for a machine.)" })); case "failed": return(Json(new AgentStatusItem() { statusMessage = $"Error state: Please contact dnceng with Job Id (Helix work item in job {correlationId} for agent {workItemId} failed. Please check the logs.)" })); default: throw new NotImplementedException( $"Got unexpected state '{workItemDetails.State}' for agent {workItemId} in job {correlationId}"); } }