diff options
| author | Ben Sima <ben@bensima.com> | 2025-11-24 15:48:17 -0500 |
|---|---|---|
| committer | Ben Sima <ben@bensima.com> | 2025-11-24 15:48:17 -0500 |
| commit | 0c6ff2172f3c48f4a6a41d95fd2da5ced183599a (patch) | |
| tree | 11d40086a34b98d046caacf3bfb66c9e1d3db772 | |
| parent | 1c77c6aa19cf73d89490ee37546e217169bb6b22 (diff) | |
Allow worker to take a specific task to work on
| -rw-r--r-- | Omni/Agent.hs | 13 | ||||
| -rw-r--r-- | Omni/Agent/Worker.hs | 37 |
2 files changed, 36 insertions, 14 deletions
diff --git a/Omni/Agent.hs b/Omni/Agent.hs index 070e3fb..b7381b8 100644 --- a/Omni/Agent.hs +++ b/Omni/Agent.hs @@ -43,7 +43,7 @@ help = agent Usage: - agent start + agent start [<task-id>] agent harvest [--path=<path>] agent merge-driver <ours> <theirs> agent test @@ -72,7 +72,9 @@ move args Core.workerPath = path } - Worker.start worker + let taskId = fmap Text.pack (Cli.getArg args (Cli.argument "task-id")) + + Worker.start worker taskId | args `Cli.has` Cli.command "harvest" = harvest args | args `Cli.has` Cli.command "merge-driver" = mergeDriver args | otherwise = putStrLn (Cli.usage help) @@ -156,6 +158,13 @@ unitTests = case result of Left err -> Test.assertFailure <| "Failed to parse 'start': " <> show err Right args -> args `Cli.has` Cli.command "start" Test.@?= True, + Test.unit "can parse start command with task id" <| do + let result = Docopt.parseArgs help ["start", "t-123"] + case result of + Left err -> Test.assertFailure <| "Failed to parse 'start t-123': " <> show err + Right args -> do + args `Cli.has` Cli.command "start" Test.@?= True + Cli.getArg args (Cli.argument "task-id") Test.@?= Just "t-123", Test.unit "can parse harvest command" <| do let result = Docopt.parseArgs help ["harvest"] case result of diff --git a/Omni/Agent/Worker.hs b/Omni/Agent/Worker.hs index c9a7563..31321f5 100644 --- a/Omni/Agent/Worker.hs +++ b/Omni/Agent/Worker.hs @@ -16,14 +16,14 @@ import System.FilePath ((</>)) import qualified System.IO as IO import qualified System.Process as Process -start :: Core.Worker -> IO () -start worker = do +start :: Core.Worker -> Maybe Text -> IO () +start worker maybeTaskId = do AgentLog.init (Core.workerName worker) AgentLog.log ("Worker starting for " <> Core.workerName worker) - runOnce worker + runOnce worker maybeTaskId -runOnce :: Core.Worker -> IO () -runOnce worker = do +runOnce :: Core.Worker -> Maybe Text -> IO () +runOnce worker maybeTaskId = do let repo = Core.workerPath worker AgentLog.updateActivity "Syncing tasks..." @@ -39,13 +39,26 @@ runOnce worker = do -- Here we rely on 'task loadTasks' reading the file. -- But 'syncWithLive' already updated the file from git. - -- Find ready work - readyTasks <- TaskCore.getReadyTasks - case readyTasks of - [] -> do - AgentLog.updateActivity "No work found." - AgentLog.log "No ready tasks found." - (task : _) -> do + -- Find work + targetTask <- case maybeTaskId of + Just tid -> do + TaskCore.findTask tid </ TaskCore.loadTasks + Nothing -> do + readyTasks <- TaskCore.getReadyTasks + case readyTasks of + [] -> pure Nothing + (task : _) -> pure (Just task) + + case targetTask of + Nothing -> do + case maybeTaskId of + Just tid -> do + AgentLog.updateActivity ("Task " <> tid <> " not found.") + AgentLog.log ("Task " <> tid <> " not found.") + Nothing -> do + AgentLog.updateActivity "No work found." + AgentLog.log "No ready tasks found." + Just task -> do processTask worker task processTask :: Core.Worker -> TaskCore.Task -> IO () |
