arbiter-simple-0.1.0.0
arbiter-simple
Safe HaskellNone
LanguageGHC2024

Arbiter.Simple.MonadArbiter

Description

postgresql-simple primitives for writing a custom MonadArbiter instance.

Handlers receive a Database.PostgreSQL.Simple.Connection for running queries inside the worker transaction:

import Arbiter.Core qualified as Arb
import Arbiter.Simple qualified as ArbS
import Database.PostgreSQL.Simple (Connection)

instance Arb.MonadArbiter MyApp where
  type RegistryOf MyApp = MyRegistry
  type Handler MyApp job result = Connection -> job -> MyApp result
  getSchema                = asks appSchema
  executeQuery             = ArbS.simpleExecuteQuery
  executeStatement         = ArbS.simpleExecuteStatement
  withDbTransaction        = ArbS.simpleWithDbTransaction
  runHandlerWithConnection = ArbS.simpleRunHandlerWithConnection
  getListener              = asks appListener

The primitives also need a HasPoolState Connection MyApp instance. See HasPoolState.

Write a handler's own signature as JobHandler MyApp MyPayload MyResult, which is Handler at that queue's job and declared result types.

Synopsis

MonadArbiter implementation

simpleExecuteQuery :: (HasPoolState Connection m, MonadUnliftIO m) => Query a -> m [a]Source #

Run a query, decoding rows.

simpleExecuteStatement :: (HasPoolState Connection m, MonadUnliftIO m) => Query a -> m Int64Source #

Run a statement, returning rows affected.

simpleWithDbTransaction :: (HasPoolState Connection m, MonadUnliftIO m) => m a -> m aSource #

Transaction bracket. Nests via savepoints.

simpleRunHandlerWithConnection :: (HasPoolState Connection m, MonadUnliftIO m) => (Connection -> job -> m result) -> job -> m resultSource #

Run a handler on the pinned connection, or on a borrowed pool connection when none is pinned.

Connection

simpleWithConnection :: (HasPoolState Connection m, MonadUnliftIO m) => m a -> m aSource #

Pin one pooled connection for the action.