Skip to content

Commit 382c4de

Browse files
committed
[cli] fix: wait even in success cases in anti-oracle
1 parent aa4ab4b commit 382c4de

File tree

1 file changed

+21
-14
lines changed

1 file changed

+21
-14
lines changed

cli/src/Oracle/Process.hs

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -130,18 +130,23 @@ processServer
130130
-> WithContext m ()
131131
processServer opts@ProcessOptions{poPollIntervalSeconds} = do
132132
liftIO $ putStrLn "Starting oracle process server..."
133-
let loop :: WithContext m () = do
133+
let waitLoop = do
134+
liftIO
135+
$ putStrLn
136+
$ "Sleeping for "
137+
++ show poPollIntervalSeconds
138+
++ " seconds..."
139+
liftIO $ threadDelay (poPollIntervalSeconds * 1000000)
140+
loop
141+
142+
loop :: WithContext m () = do
134143
liftIO $ putStrLn "Polling for new requests..."
135144
reqIds <- liftIO $ poll opts
136145
if null reqIds
137146
then do
138147
liftIO
139-
$ putStrLn
140-
$ "No new requests found. Sleeping for "
141-
++ show poPollIntervalSeconds
142-
++ " seconds..."
143-
liftIO $ threadDelay (poPollIntervalSeconds * 1000000)
144-
loop
148+
$ putStrLn "No new requests found."
149+
waitLoop
145150
else do
146151
liftIO
147152
$ putStrLn
@@ -166,19 +171,21 @@ processServer opts@ProcessOptions{poPollIntervalSeconds} = do
166171
$ putStrLn
167172
$ "Successfully submitted batch with tx hash: "
168173
++ show txHash
169-
loop
174+
waitLoop
170175
loop
171176
poll :: ProcessOptions -> IO [RequestRefId]
172177
poll ProcessOptions{poTokenId, poMPFSClient, poAuth} = do
173178
result <- cmd (GetToken poAuth poMPFSClient poTokenId)
174179
case result of
175180
ValidationFailure err -> error $ "Failed to get token: " ++ show err
176-
ValidationSuccess token -> pure
177-
$ fmap (requestZooRefId . request)
178-
$ flip filter (tokenRequests token)
179-
$ \(WithValidation v _) -> case v of
180-
ValidationFailure _err -> False
181-
ValidationSuccess Validated -> True
181+
ValidationSuccess token -> do
182+
print $ tokenRequests token
183+
pure
184+
$ fmap (requestZooRefId . request)
185+
$ flip filter (tokenRequests token)
186+
$ \(WithValidation v _) -> case v of
187+
ValidationFailure _err -> False
188+
ValidationSuccess Validated -> True
182189

183190
batch :: ProcessOptions -> [RequestRefId] -> [[RequestRefId]]
184191
batch ProcessOptions{poMaxRequestsPerBatch} = go

0 commit comments

Comments
 (0)