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 /Omni/Agent | |
| parent | 1c77c6aa19cf73d89490ee37546e217169bb6b22 (diff) | |
Allow worker to take a specific task to work on
Diffstat (limited to 'Omni/Agent')
| -rw-r--r-- | Omni/Agent/Worker.hs | 37 |
1 files changed, 25 insertions, 12 deletions
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 () |
