Skip to content

Commit

Permalink
notf pubsub (#747) (#758)
Browse files Browse the repository at this point in the history
  • Loading branch information
00abhishek0000 authored Feb 5, 2025
1 parent f4d252a commit b85fc14
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ notifyPerson cfg notificationData = do
case T.splitOn "-" notificationData.streamId of
[startUuid, midOneUuid, _, _] -> T.intercalate "-" [startUuid, midOneUuid]
_ -> notificationData.streamId
_ <- Hedis.withCrossAppRedis $ Hedis.publish "active-notification" notificationStreamId
void $ Hedis.withCrossAppRedis $ Hedis.xAddExp ("N" <> notificationStreamId <> "{" <> (show shardId) <> "}") "*" (buildFieldValue notificationData now) cfg.streamExpirationTime
where
buildFieldValue notifData createdAt =
Expand Down
21 changes: 21 additions & 0 deletions lib/mobility-core/src/Kernel/Storage/Hedis/Queries.hs
Original file line number Diff line number Diff line change
Expand Up @@ -824,3 +824,24 @@ ttl key = withLogTag "Redis" $ do
withLogTag "CLUSTER" $ logTagInfo "FAILED_TO_TTL" $ show err
pure (-1) -- Returning -1 if there was an error
Right expSec -> pure expSec

publish :: (HedisFlow m env) => Text -> Text -> m ()
publish channel message = withLogTag "Redis" $ do
migrating <- asks (.hedisMigrationStage)
when migrating $ do
res <- withTimeRedis "RedisStandalone" "publish" $
try @_ @SomeException $
runWithPrefix'_ channel $ \prefChannel ->
Hedis.publish prefChannel (BSL.toStrict $ Ae.encode message)

whenLeft res $ \err ->
withLogTag "STANDALONE" $
logTagInfo "FAILED_TO_PUBLISH" (show err)

res <- withTimeRedis "RedisCluster" "publish" $
try @_ @SomeException $
runWithPrefix_ channel $ \prefChannel ->
Hedis.publish prefChannel (BSL.toStrict $ Ae.encode message)
whenLeft res $ \err ->
withLogTag "CLUSTER" $
logTagInfo "FAILED_TO_PUBLISH" (show err)

0 comments on commit b85fc14

Please sign in to comment.