Seperated Task and TaskResult types.
This commit is contained in:
@@ -208,19 +208,19 @@ proc getTasks*(listener, agent: string): JsonNode =
|
||||
# return nil
|
||||
|
||||
# Return tasks in JSON format
|
||||
return %cq.agents[agent.toUpperAscii].tasks.filterIt(it.status != Completed)
|
||||
return %cq.agents[agent.toUpperAscii].tasks
|
||||
|
||||
proc handleResult*(listener, agent, task: string, taskResult: Task) =
|
||||
proc handleResult*(listener, agent, task: string, taskResult: TaskResult) =
|
||||
|
||||
{.cast(gcsafe).}:
|
||||
|
||||
cq.writeLine(fgBlack, styleBright, fmt"[*] [{task}] ", resetStyle, "Task execution finished.")
|
||||
|
||||
if taskResult.result != "":
|
||||
if taskResult.data != "":
|
||||
cq.writeLine(fgBlack, styleBright, fmt"[*] [{task}] ", resetStyle, "Output:")
|
||||
|
||||
# Split result string on newline to keep formatting
|
||||
for line in decode(taskResult.result).split("\n"):
|
||||
for line in decode(taskResult.data).split("\n"):
|
||||
cq.writeLine(line)
|
||||
|
||||
# Update task queue to include all tasks, except the one that was just completed
|
||||
|
||||
@@ -11,8 +11,6 @@ proc taskExecuteShell*(cq: Conquest, arguments: seq[string]) =
|
||||
agent: cq.interactAgent.name,
|
||||
command: ExecuteShell,
|
||||
args: arguments,
|
||||
result: "",
|
||||
status: Created
|
||||
)
|
||||
|
||||
# Add new task to the agent's task queue
|
||||
|
||||
@@ -20,8 +20,6 @@ proc taskExecuteSleep*(cq: Conquest, delay: int) =
|
||||
agent: cq.interactAgent.name,
|
||||
command: Sleep,
|
||||
args: @[$delay],
|
||||
result: "",
|
||||
status: Created
|
||||
)
|
||||
|
||||
# Add new task to the agent's task queue
|
||||
|
||||
@@ -101,7 +101,7 @@ proc postResults*(ctx: Context) {.async.} =
|
||||
try:
|
||||
let
|
||||
taskResultJson: JsonNode = parseJson(ctx.request.body)
|
||||
taskResult: Task = taskResultJson.to(Task)
|
||||
taskResult: TaskResult = taskResultJson.to(TaskResult)
|
||||
|
||||
# Handle and display task result
|
||||
handleResult(listener, agent, task, taskResult)
|
||||
|
||||
@@ -17,34 +17,23 @@ type
|
||||
Sleep = "sleep"
|
||||
|
||||
TaskStatus* = enum
|
||||
Created = "created"
|
||||
Completed = "completed"
|
||||
Created = "created"
|
||||
Pending = "pending"
|
||||
Failed = "failed"
|
||||
Cancelled = "cancelled"
|
||||
|
||||
TaskResult* = string
|
||||
|
||||
#[
|
||||
TaskResult*[T] = ref object
|
||||
data*: T
|
||||
|
||||
Task*[T] = ref object
|
||||
id*: string
|
||||
agent*: string
|
||||
command*: TaskCommand
|
||||
args*: seq[string]
|
||||
result*: TaskResult[T]
|
||||
status*: TaskStatus
|
||||
]#
|
||||
TaskResult* = ref object
|
||||
task*: string
|
||||
agent*: string
|
||||
data*: string
|
||||
status*: TaskStatus
|
||||
|
||||
Task* = ref object
|
||||
id*: string
|
||||
agent*: string
|
||||
command*: TaskCommand
|
||||
args*: seq[string]
|
||||
result*: TaskResult
|
||||
status*: TaskStatus
|
||||
args*: seq[string]
|
||||
|
||||
AgentRegistrationData* = object
|
||||
username*: string
|
||||
|
||||
Reference in New Issue
Block a user