Skip to content

Commit

Permalink
Merge pull request #147 from obsidiansystems/aa/beam-notify
Browse files Browse the repository at this point in the history
Add notify-listen-beam
  • Loading branch information
ali-abrar authored Nov 18, 2021
2 parents 0f43302 + 76f7b28 commit fc850b5
Show file tree
Hide file tree
Showing 6 changed files with 373 additions and 28 deletions.
2 changes: 1 addition & 1 deletion ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ This project's release branch is `master`. This log is written from the perspect
* Remove `Rhyolite.Map.Monoidal`. For `=:` use `Data.Map.Monoidal.singleton` instead, and for `restrictKeys` use monoidal-containers >= 0.6.1.0.
* Rename `PostgresRaw` to `Psql` and move it to `psql-simple-class`.
* Move Psql (formerly PostgresRaw) instance for groundhog's `DbPersist` to psql-simple-groundhog.
* Move `Rhyolite.Backend.Listen` to its own project `rhyolite-notify-listen`. The module is now called `Rhyolite.DB.NotifyListen`. `insertAndNotify` and related classes and functions can now be found in the groundhog-legacy package in the `Rhyolite.DB.NotifyListen.Groundhog` module. The various `notify` functions now require `Psql m`.
* Move `Rhyolite.Backend.Listen` to its own project `rhyolite-notify-listen`. The module is now called `Rhyolite.DB.NotifyListen`. `insertAndNotify` and related classes and functions can now be found in the groundhog-legacy package in the `Rhyolite.DB.NotifyListen.Groundhog` module, and in `notify-listen-beam` for beam versions. The various `notify` functions now require `Psql m`.
* Remove `fromIdRow` from `Rhyolite.Backend.DB.PsqlSimple`
* Remove rhyolite-aeson-orphans. It has been renamed and moved to [bytestring-aeson-orphans](https://github.com/obsidiansystems/bytestring-aeson-orphans) and is now used as a dependency.
* Remove the aeson orphan instances for Alt, Any and Down.
Expand Down
4 changes: 2 additions & 2 deletions backend/Rhyolite/Backend/App.hs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import Reflex (Group(..), Additive)

import Rhyolite.Api
import Rhyolite.App
import Rhyolite.DB.NotifyListen (startNotificationListener, defaultNotificationChannel)
import Rhyolite.DB.NotifyListen (startNotificationListener)
import Rhyolite.Concurrent
import Rhyolite.Sign (Signed)
import Rhyolite.Backend.WebSocket (withWebsocketsConnection, getDataMessage, sendEncodedDataMessage)
Expand Down Expand Up @@ -446,7 +446,7 @@ serveDbOverWebsocketsRaw
-> Pipeline IO (MonoidalMap ClientKey q) q'
-> IO (m a, IO ())
serveDbOverWebsocketsRaw withWsConn version fromWire db handleApi handleNotify handleQuery pipe = do
(getNextNotification, finalizeListener) <- startNotificationListener defaultNotificationChannel db
(getNextNotification, finalizeListener) <- startNotificationListener db
rec (qh, finalizeFeed) <- feedPipeline (handleNotify <$> getNextNotification) handleQuery r
(qh', r) <- unPipeline pipe qh r'
(r', handleListen) <- connectPipelineToWebsocketsRaw withWsConn version fromWire handleApi qh'
Expand Down
9 changes: 3 additions & 6 deletions groundhog-legacy/src/Rhyolite/DB/NotifyListen/Groundhog.hs
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,18 @@ import Rhyolite.DB.NotifyListen (NotificationType(..))
import Database.PostgreSQL.Simple.Class
import GHC.Generics

notifyChannel :: NL.NotificationChannel
notifyChannel = NL.defaultNotificationChannel

notificationListener
:: (FromJSON notifyMessage)
=> Pool Postgresql
-> IO (TChan notifyMessage, IO ())
notificationListener = NL.notificationListener notifyChannel . coerce
notificationListener = NL.notificationListener . coerce

startNotificationListener
:: FromJSON notifyMessage
=> Pool Postgresql
-> IO (IO notifyMessage, IO ())
startNotificationListener =
NL.startNotificationListener notifyChannel . coerce
NL.startNotificationListener . coerce

notify
:: ( Has' ToJSON n Identity
Expand All @@ -67,7 +64,7 @@ notify
-> n a
-> a
-> m ()
notify nt n a = NL.notify notifyChannel nt n a
notify nt n a = NL.notify nt n a

-- | Class for relating application-specific db notification types with db
-- entity types.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ extra-source-files: CHANGELOG.md
library
exposed-modules: Rhyolite.DB.NotifyListen.Beam
build-depends: base
, aeson
, beam-core
, beam-postgres
, constraints
, constraints-extras
, psql-simple-class
, psql-simple-beam
, rhyolite-notify-listen
, these
hs-source-dirs: src
default-language: Haskell2010
Loading

0 comments on commit fc850b5

Please sign in to comment.