2025-07-09 14:38:30 +02:00
|
|
|
import strutils, tables, json
|
2025-07-18 18:47:57 +02:00
|
|
|
import ../types
|
|
|
|
|
import ../commands/commands
|
|
|
|
|
import sugar
|
2025-05-22 20:03:22 +02:00
|
|
|
|
2025-07-18 18:47:57 +02:00
|
|
|
proc handleTask*(config: AgentConfig, task: Task): TaskResult =
|
2025-07-08 23:10:19 +02:00
|
|
|
|
2025-07-18 18:47:57 +02:00
|
|
|
dump task
|
|
|
|
|
|
|
|
|
|
# var taskResult = TaskResult
|
2025-07-18 14:24:07 +02:00
|
|
|
# let handlers = {
|
|
|
|
|
# CMD_SLEEP: taskSleep,
|
|
|
|
|
# CMD_SHELL: taskShell,
|
|
|
|
|
# CMD_PWD: taskPwd,
|
|
|
|
|
# CMD_CD: taskCd,
|
|
|
|
|
# CMD_LS: taskDir,
|
|
|
|
|
# CMD_RM: taskRm,
|
|
|
|
|
# CMD_RMDIR: taskRmdir,
|
|
|
|
|
# CMD_MOVE: taskMove,
|
|
|
|
|
# CMD_COPY: taskCopy
|
|
|
|
|
# }.toTable
|
2025-05-28 10:39:30 +02:00
|
|
|
|
2025-07-08 23:10:19 +02:00
|
|
|
# Handle task command
|
2025-07-18 14:24:07 +02:00
|
|
|
# taskResult = handlers[task.command](task)
|
|
|
|
|
# echo taskResult.data
|
2025-05-22 20:03:22 +02:00
|
|
|
|
2025-07-08 23:10:19 +02:00
|
|
|
# Handle actions on specific commands
|
2025-07-18 14:24:07 +02:00
|
|
|
# case task.command:
|
|
|
|
|
# of CMD_SLEEP:
|
|
|
|
|
# if taskResult.status == STATUS_COMPLETED:
|
|
|
|
|
# # config.sleep = parseJson(task.args)["delay"].getInt()
|
|
|
|
|
# discard
|
|
|
|
|
# else:
|
|
|
|
|
# discard
|
2025-07-08 23:10:19 +02:00
|
|
|
|
2025-07-18 14:24:07 +02:00
|
|
|
# # Return the result
|
|
|
|
|
# return taskResult
|