summaryrefslogtreecommitdiff
path: root/Omni/Agent
diff options
context:
space:
mode:
Diffstat (limited to 'Omni/Agent')
-rw-r--r--Omni/Agent/Worker.hs12
1 files changed, 6 insertions, 6 deletions
diff --git a/Omni/Agent/Worker.hs b/Omni/Agent/Worker.hs
index 4ff9042..7afc849 100644
--- a/Omni/Agent/Worker.hs
+++ b/Omni/Agent/Worker.hs
@@ -227,8 +227,7 @@ monitorLog :: FilePath -> IO ()
monitorLog logPath = do
waitForFile logPath
IO.withFile logPath IO.ReadMode <| \h -> do
- -- Tail the file
- IO.hSeek h IO.SeekFromEnd 0
+ -- Start from beginning of file (don't seek to end)
forever <| do
eof <- IO.hIsEOF h
if eof
@@ -263,11 +262,12 @@ parseAndUpdate line = do
_ -> pure ()
-- Extract cost from usage-ledger:event
- -- Pattern: {"addedCredits": 0.123, "message": "usage-ledger:event", ...}
- case KM.lookup "addedCredits" obj of
+ -- Pattern: {"totalCredits": 1.54, "message": "usage-ledger:event", ...}
+ -- We use totalCredits to be robust against missed lines and restarts.
+ case KM.lookup "totalCredits" obj of
Just (Aeson.Number n) ->
- let cost = Scientific.toRealFloat n
- in AgentLog.update (\s -> s {AgentLog.statusCredits = AgentLog.statusCredits s + cost})
+ let total = Scientific.toRealFloat n
+ in AgentLog.update (\s -> s {AgentLog.statusCredits = total})
_ -> pure ()
timeTicker :: IO ()