Skip to content
This repository has been archived by the owner on Nov 1, 2023. It is now read-only.

Commit

Permalink
Remove some response-only properties from the Task model (#2335)
Browse files Browse the repository at this point in the history
  • Loading branch information
Porges committed Sep 1, 2022
1 parent 440f19b commit 52ba57b
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 13 deletions.
39 changes: 28 additions & 11 deletions src/ApiService/ApiService/Functions/Tasks.cs
@@ -1,4 +1,5 @@
using System.Net;
using System.Threading.Tasks;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Azure.Functions.Worker.Http;

Expand Down Expand Up @@ -31,20 +32,36 @@ public class Tasks {
return await _context.RequestHandling.NotOk(req, request.ErrorV, "task get");
}

if (request.OkV.TaskId != null) {
var task = await _context.TaskOperations.GetByTaskId(request.OkV.TaskId.Value);
if (request.OkV.TaskId is Guid taskId) {
var task = await _context.TaskOperations.GetByTaskId(taskId);
if (task == null) {
return await _context.RequestHandling.NotOk(req, new Error(ErrorCode.INVALID_REQUEST, new[] { "unable to find task"
}), "task get");

return await _context.RequestHandling.NotOk(
req,
new Error(
ErrorCode.INVALID_REQUEST,
new[] { "unable to find task" }),
"task get");
}
task.Nodes = await _context.NodeTasksOperations.GetNodeAssignments(request.OkV.TaskId.Value).ToListAsync();
task.Events = await _context.TaskEventOperations.GetSummary(request.OkV.TaskId.Value).ToListAsync();

var response = req.CreateResponse(HttpStatusCode.OK);
await response.WriteAsJsonAsync(task);
return response;

var (nodes, events) = await (
_context.NodeTasksOperations.GetNodeAssignments(taskId).ToListAsync().AsTask(),
_context.TaskEventOperations.GetSummary(taskId).ToListAsync().AsTask());

var result = new TaskSearchResult(
JobId: task.JobId,
TaskId: task.TaskId,
State: task.State,
Os: task.Os,
Config: task.Config,
Error: task.Error,
Auth: task.Auth,
Heartbeat: task.Heartbeat,
EndTime: task.EndTime,
UserInfo: task.UserInfo,
Nodes: nodes,
Events: events);

return await RequestHandling.Ok(req, result);
}

var tasks = await _context.TaskOperations.SearchAll().ToListAsync();
Expand Down
2 changes: 0 additions & 2 deletions src/ApiService/ApiService/OneFuzzTypes/Model.cs
Expand Up @@ -256,8 +256,6 @@ public record Task(
DateTimeOffset? Heartbeat = null,
DateTimeOffset? EndTime = null,
UserInfo? UserInfo = null) : StatefulEntityBase<TaskState>(State) {
public List<TaskEventSummary> Events { get; set; } = new List<TaskEventSummary>();
public List<NodeAssignment> Nodes { get; set; } = new List<NodeAssignment>();
}

public record TaskEvent(
Expand Down
15 changes: 15 additions & 0 deletions src/ApiService/ApiService/OneFuzzTypes/Responses.cs
Expand Up @@ -35,6 +35,21 @@ public record NodeSearchResult(
bool DebugKeepNode
) : BaseResponse();

public record TaskSearchResult(
Guid JobId,
Guid TaskId,
TaskState State,
Os Os,
TaskConfig Config,
Error? Error,
Authentication? Auth,
DateTimeOffset? Heartbeat,
DateTimeOffset? EndTime,
UserInfo? UserInfo,
List<TaskEventSummary> Events,
List<NodeAssignment> Nodes
) : BaseResponse();

public record BoolResult(
bool Result
) : BaseResponse();
Expand Down

0 comments on commit 52ba57b

Please sign in to comment.