@@ -480,8 +480,8 @@ subscribeSrvSubs ca st batchSize (srv, srvId, service_) = do
480480
481481-- this function is concurrency-safe - only onle subscriber per server can be created at a time,
482482-- other threads would wait for the first thread to create it.
483- subscribeNtfs :: NtfSubscriber -> NtfPostgresStore -> SMPServer -> ServerNtfSub -> IO ()
484- subscribeNtfs NtfSubscriber {smpSubscribers, subscriberSeq, smpAgent = ca} st smpServer ntfSub =
483+ subscribeNtfs :: NtfSubscriber -> NtfPostgresStore -> SMPServer -> Int64 -> ServerNtfSub -> IO ()
484+ subscribeNtfs NtfSubscriber {smpSubscribers, subscriberSeq, smpAgent = ca} st smpServer srvId ntfSub =
485485 getSubscriberVar
486486 >>= either createSMPSubscriber waitForSMPSubscriber
487487 >>= mapM_ (\ sub -> atomically $ writeTQueue (subscriberSubQ sub) ntfSub)
@@ -493,8 +493,8 @@ subscribeNtfs NtfSubscriber {smpSubscribers, subscriberSeq, smpAgent = ca} st sm
493493 createSMPSubscriber v =
494494 E. handle (\ (e :: SomeException ) -> logError (" SMP subscriber exception: " <> tshow e) >> removeSubscriber v) $ do
495495 q <- newTQueueIO
496- tId <- mkWeakThreadId =<< forkIO (runSMPSubscriber q)
497- let sub = SMPSubscriber {smpServer, subscriberSubQ = q, subThreadId = tId}
496+ tId <- mkWeakThreadId =<< forkIO (runSMPSubscriber smpServer srvId q)
497+ let sub = SMPSubscriber {smpServer, smpServerId = srvId, subscriberSubQ = q, subThreadId = tId}
498498 atomically $ putTMVar (sessionVar v) sub -- this makes it available for other threads
499499 pure $ Just sub
500500
@@ -510,13 +510,13 @@ subscribeNtfs NtfSubscriber {smpSubscribers, subscriberSeq, smpAgent = ca} st sm
510510 atomically $ removeSessVar v smpServer smpSubscribers
511511 pure Nothing
512512
513- runSMPSubscriber :: TQueue ServerNtfSub -> IO ()
514- runSMPSubscriber q = forever $ do
513+ runSMPSubscriber :: SMPServer -> Int64 -> TQueue ServerNtfSub -> IO ()
514+ runSMPSubscriber smpServer' srvId' q = forever $ do
515515 -- TODO [ntfdb] possibly, the subscriptions can be batched here and sent every say 5 seconds
516516 -- this should be analysed once we have prometheus stats
517517 (nId, sub) <- atomically $ readTQueue q
518- void $ updateSubStatus st nId NSPending
519- subscribeQueuesNtfs ca smpServer [sub]
518+ void $ updateSubStatus st srvId' nId NSPending
519+ subscribeQueuesNtfs ca smpServer' [sub]
520520
521521ntfSubscriber :: NtfSubscriber -> M ()
522522ntfSubscriber NtfSubscriber {smpAgent = ca@ SMPClientAgent {msgQ, agentQ}} =
@@ -866,12 +866,12 @@ client NtfServerClient {rcvQ, sndQ} ns@NtfSubscriber {smpAgent = ca} NtfPushServ
866866 let sub = mkNtfSubRec subId newSub
867867 resp <-
868868 withNtfStore (`addNtfSubscription` sub) $ \ case
869- True -> do
869+ (srvId, True ) -> do
870870 st <- asks store
871- liftIO $ subscribeNtfs ns st srv (subId, (nId, nKey))
871+ liftIO $ subscribeNtfs ns st srv srvId (subId, (nId, nKey))
872872 incNtfStat subCreated
873873 pure $ NRSubId subId
874- False -> pure $ NRErr AUTH
874+ (_, False ) -> pure $ NRErr AUTH
875875 pure (corrId, NoEntity , resp)
876876 NtfReqCmd SSubscription (NtfSub NtfSubRec {ntfSubId, smpQueue = SMPQueueNtf {smpServer, notifierId}, notifierKey = registeredNKey, subStatus}) (corrId, subId, cmd) -> do
877877 (corrId,subId,) <$> case cmd of
0 commit comments