| Copyright | (c) 2024 |
|---|---|
| License | BSD3 |
| Maintainer | maintainer@example.com |
| Stability | experimental |
| Safe Haskell | None |
| Language | GHC2021 |
Hindsight.Store.PostgreSQL.Events.Subscription
Description
This module provides a decentralized, pull-based subscription system where each subscriber is a self-contained agent.
Design
The architecture consists of two main components:
- The Notifier: A single, lightweight process that listens for a generic "new event" notification from PostgreSQL and broadcasts a simple "tick" to all active subscribers.
- The Subscriber Worker: Each subscription runs in its own thread. The worker pulls data from the database in a unified loop, naturally handling both catch-up and real-time processing. It is responsible for its own state management and data fetching.
This design eliminates the complexity and bottlenecks of a centralized manager, provides inherent backpressure, and leverages the database for efficient filtering.
Synopsis
- startNotifier :: MonadIO m => ByteString -> m Notifier
- shutdownNotifier :: Notifier -> IO ()
- subscribe :: forall m (ts :: [Symbol]). MonadUnliftIO m => SQLStoreHandle -> EventMatcher ts SQLStore m -> EventSelector SQLStore -> m (SubscriptionHandle SQLStore)
- data RetryPolicy = RetryPolicy {}
- data RetryConfig = RetryConfig {}
Documentation
startNotifier :: MonadIO m => ByteString -> m Notifier Source #
Starts the notifier thread. This should be created once per application and shared.
shutdownNotifier :: Notifier -> IO () Source #
Stops the notifier thread and waits for it to terminate.
This ensures the notifier is fully stopped before returning, preventing connection attempts after database shutdown.
subscribe :: forall m (ts :: [Symbol]). MonadUnliftIO m => SQLStoreHandle -> EventMatcher ts SQLStore m -> EventSelector SQLStore -> m (SubscriptionHandle SQLStore) Source #
The main subscription function. It replaces the old, complex manager-based subscription.
data RetryPolicy Source #
Retry policy for different error types
Constructors
| RetryPolicy | |
Fields
| |
Instances
data RetryConfig Source #
Default retry policies for different error scenarios
Constructors
| RetryConfig | |
Instances
| Generic RetryConfig Source # | |||||
Defined in Hindsight.Store.PostgreSQL.Events.Subscription Associated Types
| |||||
| Show RetryConfig Source # | |||||
Defined in Hindsight.Store.PostgreSQL.Events.Subscription Methods showsPrec :: Int -> RetryConfig -> ShowS # show :: RetryConfig -> String # showList :: [RetryConfig] -> ShowS # | |||||
| Eq RetryConfig Source # | |||||
| type Rep RetryConfig Source # | |||||
Defined in Hindsight.Store.PostgreSQL.Events.Subscription type Rep RetryConfig = D1 ('MetaData "RetryConfig" "Hindsight.Store.PostgreSQL.Events.Subscription" "hindsight-postgresql-store-0.1.0.0-inplace" 'False) (C1 ('MetaCons "RetryConfig" 'PrefixI 'True) (S1 ('MetaSel ('Just "connectionRetryPolicy") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 (Maybe RetryPolicy)) :*: (S1 ('MetaSel ('Just "sessionRetryPolicy") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 (Maybe RetryPolicy)) :*: S1 ('MetaSel ('Just "timeoutRetryPolicy") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 (Maybe RetryPolicy))))) | |||||