diff options
| author | Ben Sima <ben@bensima.com> | 2025-11-27 10:22:47 -0500 |
|---|---|---|
| committer | Ben Sima <ben@bensima.com> | 2025-11-27 10:22:47 -0500 |
| commit | 33832022b7b4e3cd22f2503c09537af1e577d973 (patch) | |
| tree | 7ae5ea5a0835c3b0d4589f1d5a31ff0fd94b6fb5 /Omni/Task | |
| parent | adbd169dc75337ba1d2884262fa6325ae386ae25 (diff) | |
Add views for blocked and needs-intervention tasks
The build passes with no errors. The implementation was already
in place
Task-Id: t-149.6
Diffstat (limited to 'Omni/Task')
| -rw-r--r-- | Omni/Task/Core.hs | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/Omni/Task/Core.hs b/Omni/Task/Core.hs index 4e65581..3a71900 100644 --- a/Omni/Task/Core.hs +++ b/Omni/Task/Core.hs @@ -1026,3 +1026,47 @@ getActivitiesForTask tid = where readStage :: Text -> ActivityStage readStage s = fromMaybe Claiming (readMaybe (T.unpack s)) + +-- | Get tasks with unmet blocking dependencies (not ready, not done) +getBlockedTasks :: IO [Task] +getBlockedTasks = do + allTasks <- loadTasks + readyTasks <- getReadyTasks + let readyIds = map taskId readyTasks + doneIds = [taskId t | t <- allTasks, taskStatus t == Done] + isBlocked task = + taskStatus task + `elem` [Open, InProgress] + && taskId task + `notElem` readyIds + && taskId task + `notElem` doneIds + pure [t | t <- allTasks, isBlocked t] + +-- | Get tasks that have failed 3+ times and need human intervention +getInterventionTasks :: IO [Task] +getInterventionTasks = do + allTasks <- loadTasks + retryContexts <- getAllRetryContexts + let highRetryIds = [retryTaskId ctx | ctx <- retryContexts, retryAttempt ctx >= 3] + pure [t | t <- allTasks, taskId t `elem` highRetryIds] + +-- | Get all retry contexts from the database +getAllRetryContexts :: IO [RetryContext] +getAllRetryContexts = + withDb <| \conn -> do + rows <- + SQL.query_ + conn + "SELECT task_id, original_commit, conflict_files, attempt, reason FROM retry_context" :: + IO [(Text, Text, Text, Int, Text)] + pure + [ RetryContext + { retryTaskId = tid, + retryOriginalCommit = commit, + retryConflictFiles = fromMaybe [] (decode (BLC.pack (T.unpack filesJson))), + retryAttempt = attempt, + retryReason = reason + } + | (tid, commit, filesJson, attempt, reason) <- rows + ] |
