2025-05-29 15:26:50 +02:00
|
|
|
import strutils
|
2025-05-22 20:03:22 +02:00
|
|
|
import ./types
|
|
|
|
|
import ./commands/commands
|
|
|
|
|
|
2025-05-29 15:26:50 +02:00
|
|
|
proc handleTask*(task: Task, config: AgentConfig): TaskResult =
|
2025-05-22 20:03:22 +02:00
|
|
|
|
|
|
|
|
# Handle task command
|
|
|
|
|
case task.command:
|
2025-05-28 10:39:30 +02:00
|
|
|
|
2025-05-22 20:03:22 +02:00
|
|
|
of ExecuteShell:
|
2025-05-29 15:26:50 +02:00
|
|
|
let taskResult = taskShell(task)
|
|
|
|
|
echo taskResult.data
|
|
|
|
|
return taskResult
|
2025-05-22 20:03:22 +02:00
|
|
|
|
2025-05-29 15:26:50 +02:00
|
|
|
of Sleep:
|
2025-05-28 10:39:30 +02:00
|
|
|
# Execute task
|
2025-05-29 15:26:50 +02:00
|
|
|
let taskResult = taskSleep(task)
|
2025-05-28 10:39:30 +02:00
|
|
|
|
|
|
|
|
# Update sleep delay in agent config
|
2025-05-29 15:26:50 +02:00
|
|
|
if taskResult.status == Completed:
|
2025-06-02 21:14:13 +02:00
|
|
|
config.sleep = parseInt(task.args[0])
|
2025-05-28 10:39:30 +02:00
|
|
|
|
|
|
|
|
# Return result
|
2025-05-29 15:26:50 +02:00
|
|
|
return taskResult
|
2025-05-28 10:39:30 +02:00
|
|
|
|
2025-05-22 20:03:22 +02:00
|
|
|
else:
|
|
|
|
|
echo "Not implemented"
|
2025-05-29 15:26:50 +02:00
|
|
|
return nil
|