hindsight-postgresql-store
Copyright(c) 2024
LicenseBSD3
Maintainermaintainer@example.com
Stabilityexperimental
Safe HaskellNone
LanguageGHC2021

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:

  1. 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.
  2. 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

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

Instances

Instances details
Generic RetryPolicy Source # 
Instance details

Defined in Hindsight.Store.PostgreSQL.Events.Subscription

Associated Types

type Rep RetryPolicy 
Instance details

Defined in Hindsight.Store.PostgreSQL.Events.Subscription

type Rep RetryPolicy = D1 ('MetaData "RetryPolicy" "Hindsight.Store.PostgreSQL.Events.Subscription" "hindsight-postgresql-store-0.1.0.0-inplace" 'False) (C1 ('MetaCons "RetryPolicy" 'PrefixI 'True) ((S1 ('MetaSel ('Just "maxRetries") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 Int) :*: S1 ('MetaSel ('Just "baseDelayMs") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 Int)) :*: (S1 ('MetaSel ('Just "maxDelayMs") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 Int) :*: (S1 ('MetaSel ('Just "backoffMultiplier") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 Double) :*: S1 ('MetaSel ('Just "jitterPercent") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 Double)))))
Show RetryPolicy Source # 
Instance details

Defined in Hindsight.Store.PostgreSQL.Events.Subscription

Eq RetryPolicy Source # 
Instance details

Defined in Hindsight.Store.PostgreSQL.Events.Subscription

type Rep RetryPolicy Source # 
Instance details

Defined in Hindsight.Store.PostgreSQL.Events.Subscription

type Rep RetryPolicy = D1 ('MetaData "RetryPolicy" "Hindsight.Store.PostgreSQL.Events.Subscription" "hindsight-postgresql-store-0.1.0.0-inplace" 'False) (C1 ('MetaCons "RetryPolicy" 'PrefixI 'True) ((S1 ('MetaSel ('Just "maxRetries") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 Int) :*: S1 ('MetaSel ('Just "baseDelayMs") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 Int)) :*: (S1 ('MetaSel ('Just "maxDelayMs") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 Int) :*: (S1 ('MetaSel ('Just "backoffMultiplier") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 Double) :*: S1 ('MetaSel ('Just "jitterPercent") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 Double)))))

data RetryConfig Source #

Default retry policies for different error scenarios

Instances

Instances details
Generic RetryConfig Source # 
Instance details

Defined in Hindsight.Store.PostgreSQL.Events.Subscription

Associated Types

type Rep RetryConfig 
Instance details

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)))))
Show RetryConfig Source # 
Instance details

Defined in Hindsight.Store.PostgreSQL.Events.Subscription

Eq RetryConfig Source # 
Instance details

Defined in Hindsight.Store.PostgreSQL.Events.Subscription

type Rep RetryConfig Source # 
Instance details

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)))))