Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ntf: add logs to client forever loops #1342

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/Simplex/Messaging/Agent/Client.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1865,11 +1865,13 @@
noWork = liftIO $ noWorkToDo doWork
notifyErr err e = atomically $ writeTBQueue (subQ c) ("", "", AEvt SAEConn $ ERR $ err $ show e)

withWorkItems :: AgentClient -> TMVar () -> (DB.Connection -> IO (Either StoreError [Either StoreError a])) -> (NonEmpty a -> AM ()) -> AM ()
withWorkItems c doWork getWork action = do
withWorkItems :: String -> AgentClient -> TMVar () -> (DB.Connection -> IO (Either StoreError [Either StoreError a])) -> (NonEmpty a -> AM ()) -> AM ()
withWorkItems str c doWork getWork action = do
withStore' c getWork >>= \case
Right [] -> noWork
Right rs -> do
let (errs, items) = partitionEithers rs
liftIO $ print $ "withWorkItems - " <> str <> " - length items = " <> show (length items) <> ", length errs = " <> show (length errs)
case L.nonEmpty items of
Just items' -> action items'
Nothing -> do
Expand Down Expand Up @@ -2027,7 +2029,7 @@
SEDatabaseBusy e -> CRITICAL True $ B.unpack e
e -> INTERNAL $ show e

userServers :: forall p. (ProtocolTypeI p, UserProtocol p) => AgentClient -> TMap UserId (UserServers p)

Check warning on line 2032 in src/Simplex/Messaging/Agent/Client.hs

View workflow job for this annotation

GitHub Actions / build-ubuntu-20.04-9.6.3

Redundant constraint: UserProtocol p

Check warning on line 2032 in src/Simplex/Messaging/Agent/Client.hs

View workflow job for this annotation

GitHub Actions / build-ubuntu-22.04-9.6.3

Redundant constraint: UserProtocol p
userServers c = case protocolTypeI @p of
SPSMP -> smpServers c
SPXFTP -> xftpServers c
Expand Down
9 changes: 7 additions & 2 deletions src/Simplex/Messaging/Agent/NtfSubSupervisor.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}
{-# OPTIONS_GHC -fno-warn-ambiguous-fields #-}

Check warning on line 10 in src/Simplex/Messaging/Agent/NtfSubSupervisor.hs

View workflow job for this annotation

GitHub Actions / build-ubuntu-20.04-8.10.7

unrecognised warning flag: -fno-warn-ambiguous-fields

Check warning on line 10 in src/Simplex/Messaging/Agent/NtfSubSupervisor.hs

View workflow job for this annotation

GitHub Actions / build-ubuntu-20.04-8.10.7

unrecognised warning flag: -fno-warn-ambiguous-fields

module Simplex.Messaging.Agent.NtfSubSupervisor
( runNtfSupervisor,
Expand Down Expand Up @@ -59,6 +59,7 @@
runNtfSupervisor c = do
ns <- asks ntfSupervisor
forever $ do
liftIO $ print "#################### runNtfSupervisor - in forever loop"

Check warning on line 62 in src/Simplex/Messaging/Agent/NtfSubSupervisor.hs

View workflow job for this annotation

GitHub Actions / build-ubuntu-20.04-9.6.3

• Defaulting the type variable ‘a0’ to type ‘String’ in the following constraints

Check warning on line 62 in src/Simplex/Messaging/Agent/NtfSubSupervisor.hs

View workflow job for this annotation

GitHub Actions / build-ubuntu-22.04-9.6.3

• Defaulting the type variable ‘a0’ to type ‘String’ in the following constraints
cmd <- atomically . readTBQueue $ ntfSubQ ns
handleErr . agentOperationBracket c AONtfNetwork waitUntilActive $
runExceptT (processNtfCmd c cmd) >>= \case
Expand Down Expand Up @@ -196,13 +197,14 @@
runNtfWorker :: AgentClient -> NtfServer -> Worker -> AM ()
runNtfWorker c srv Worker {doWork} =
forever $ do
liftIO $ print "#################### runNtfWorker - in forever loop"

Check warning on line 200 in src/Simplex/Messaging/Agent/NtfSubSupervisor.hs

View workflow job for this annotation

GitHub Actions / build-ubuntu-20.04-9.6.3

• Defaulting the type variable ‘a0’ to type ‘String’ in the following constraints

Check warning on line 200 in src/Simplex/Messaging/Agent/NtfSubSupervisor.hs

View workflow job for this annotation

GitHub Actions / build-ubuntu-22.04-9.6.3

• Defaulting the type variable ‘a0’ to type ‘String’ in the following constraints
waitForWork doWork
ExceptT $ agentOperationBracket c AONtfNetwork throwWhenInactive $ runExceptT runNtfOperation
where
runNtfOperation :: AM ()
runNtfOperation = do
ntfBatchSize <- asks $ ntfBatchSize . config
withWorkItems c doWork (\db -> getNextNtfSubNTFActions db srv ntfBatchSize) $ \nextSubs -> do
withWorkItems "runNtfWorker" c doWork (\db -> getNextNtfSubNTFActions db srv ntfBatchSize) $ \nextSubs -> do
logInfo $ "runNtfWorker - length nextSubs = " <> tshow (length nextSubs)
currTs <- liftIO getCurrentTime
let (creates, checks, deletes, rotates) = splitActions currTs nextSubs
Expand Down Expand Up @@ -364,15 +366,18 @@

runNtfSMPWorker :: AgentClient -> SMPServer -> Worker -> AM ()
runNtfSMPWorker c srv Worker {doWork} = forever $ do
ts <- liftIO getCurrentTime
liftIO $ print $ "#################### runNtfSMPWorker - in forever loop - ts = " <> show ts
waitForWork doWork
ExceptT $ agentOperationBracket c AONtfNetwork throwWhenInactive $ runExceptT runNtfSMPOperation
where
runNtfSMPOperation :: AM ()
runNtfSMPOperation = do
ntfBatchSize <- asks $ ntfBatchSize . config
withWorkItems c doWork (\db -> getNextNtfSubSMPActions db srv ntfBatchSize) $ \nextSubs -> do
withWorkItems "runNtfSMPWorker" c doWork (\db -> getNextNtfSubSMPActions db srv ntfBatchSize) $ \nextSubs -> do
logInfo $ "runNtfSMPWorker - length nextSubs = " <> tshow (length nextSubs)
let (creates, deletes) = splitActions nextSubs
liftIO $ print $ "runNtfSMPWorker - length nextSubs = " <> tshow (length nextSubs) <> ", length creates = " <> tshow (length creates) <> ", length deletes = " <> tshow (length deletes)
retrySubActions c creates createNotifierKeys
retrySubActions c deletes deleteNotifierKeys
splitActions :: NonEmpty (NtfSubSMPAction, NtfSubscription) -> ([NtfSubscription], [NtfSubscription])
Expand Down
Loading