Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- data WorkerRegistry key resource
- empty :: Ord key => IO ( WorkerRegistry key resource)
- lookup :: ( MonadIO m, Ord key) => WorkerRegistry key resource -> key -> m ( Maybe ( Worker key resource))
- register :: forall resource ctx key msg. ( Ord key, key ~ WorkerKey ctx, msg ~ WorkerMsg ctx, HasLogger IO ( WorkerLog key msg) ctx, HasWorkerCtx resource ctx) => WorkerRegistry key resource -> ctx -> key -> MkWorker key resource msg ctx -> IO ( Maybe ( Worker key resource))
- unregister :: Ord key => WorkerRegistry key resource -> key -> IO ()
- data Worker key resource
-
data
MkWorker
key resource msg ctx =
MkWorker
{
- workerBefore :: WorkerCtx ctx -> key -> IO ()
- workerMain :: WorkerCtx ctx -> key -> IO ()
- workerAfter :: Tracer IO ( WorkerLog key msg) -> Either SomeException () -> IO ()
- workerAcquire :: (resource -> IO ()) -> IO ()
- defaultWorkerAfter :: Tracer IO ( WorkerLog key msg) -> Either SomeException a -> IO ()
- workerThread :: Worker key resource -> ThreadId
- workerId :: Worker key resource -> key
- workerResource :: Worker key resource -> resource
- class HasType resource ( WorkerCtx ctx) => HasWorkerCtx resource ctx where
-
data
WorkerLog
key msg
- = MsgThreadAfter AfterThreadLog
- | MsgFromWorker key msg
- data AfterThreadLog
- traceAfterThread :: Tracer m AfterThreadLog -> Either SomeException a -> m ()
Worker Registry
data WorkerRegistry key resource Source #
A registry to keep track of worker threads and acquired resources.
lookup :: ( MonadIO m, Ord key) => WorkerRegistry key resource -> key -> m ( Maybe ( Worker key resource)) Source #
Lookup the registry for a given worker
register :: forall resource ctx key msg. ( Ord key, key ~ WorkerKey ctx, msg ~ WorkerMsg ctx, HasLogger IO ( WorkerLog key msg) ctx, HasWorkerCtx resource ctx) => WorkerRegistry key resource -> ctx -> key -> MkWorker key resource msg ctx -> IO ( Maybe ( Worker key resource)) Source #
Register a new worker for a given key.
A worker maintains an acquired resource. It expects a task as an argument and will terminate as soon as its task is over. In practice, we provide a never-ending task that keeps the worker alive forever.
Returns
Nothing
if the worker fails to acquire the necessary resource or
terminates unexpectedly before entering its
main
action.
unregister :: Ord key => WorkerRegistry key resource -> key -> IO () Source #
Unregister a worker from the registry, terminating the running task.
Worker
data Worker key resource Source #
A worker which holds and manipulate a particular acquired resource. That resource can be, for example, a handle to a database connection.
Instances
Generic ( Worker key resource) Source # | |
type Rep ( Worker key resource) Source # | |
Defined in Cardano.Wallet.Registry
type
Rep
(
Worker
key resource) =
D1
('
MetaData
"Worker" "Cardano.Wallet.Registry" "cardano-wallet-core-2022.7.1-AGKhlyz9liLKN3QqZD1gj" '
False
) (
C1
('
MetaCons
"Worker" '
PrefixI
'
True
) (
S1
('
MetaSel
('
Just
"workerId") '
NoSourceUnpackedness
'
NoSourceStrictness
'
DecidedLazy
) (
Rec0
key)
:*:
(
S1
('
MetaSel
('
Just
"workerThread") '
NoSourceUnpackedness
'
NoSourceStrictness
'
DecidedLazy
) (
Rec0
ThreadId
)
:*:
S1
('
MetaSel
('
Just
"workerResource") '
NoSourceUnpackedness
'
NoSourceStrictness
'
DecidedLazy
) (
Rec0
resource))))
|
data MkWorker key resource msg ctx Source #
See
register
MkWorker | |
|
defaultWorkerAfter :: Tracer IO ( WorkerLog key msg) -> Either SomeException a -> IO () Source #
workerThread :: Worker key resource -> ThreadId Source #
workerResource :: Worker key resource -> resource Source #
Context
class HasType resource ( WorkerCtx ctx) => HasWorkerCtx resource ctx where Source #
A class to link an existing context to a worker context.
hoistResource :: resource -> ( WorkerMsg ctx -> WorkerLog ( WorkerKey ctx) ( WorkerMsg ctx)) -> ctx -> WorkerCtx ctx Source #
Logging
data WorkerLog key msg Source #
Log messages relating to a registry worker thread.
Instances
( Eq key, Eq msg) => Eq ( WorkerLog key msg) Source # | |
( Show key, Show msg) => Show ( WorkerLog key msg) Source # | |
( ToText key, ToText msg) => ToText ( WorkerLog key msg) Source # | |
HasPrivacyAnnotation ( WorkerLog key msg) Source # | |
Defined in Cardano.Wallet.Registry getPrivacyAnnotation :: WorkerLog key msg -> PrivacyAnnotation |
|
HasSeverityAnnotation msg => HasSeverityAnnotation ( WorkerLog key msg) Source # | |
Defined in Cardano.Wallet.Registry getSeverityAnnotation :: WorkerLog key msg -> Severity |
data AfterThreadLog Source #
Log messages describing how a worker thread exits.
Instances
Eq AfterThreadLog Source # | |
Defined in Cardano.Wallet.Registry (==) :: AfterThreadLog -> AfterThreadLog -> Bool Source # (/=) :: AfterThreadLog -> AfterThreadLog -> Bool Source # |
|
Show AfterThreadLog Source # | |
Defined in Cardano.Wallet.Registry |
|
ToText AfterThreadLog Source # | |
Defined in Cardano.Wallet.Registry toText :: AfterThreadLog -> Text Source # |
|
HasPrivacyAnnotation AfterThreadLog Source # | |
Defined in Cardano.Wallet.Registry getPrivacyAnnotation :: AfterThreadLog -> PrivacyAnnotation |
|
HasSeverityAnnotation AfterThreadLog Source # | |
Defined in Cardano.Wallet.Registry getSeverityAnnotation :: AfterThreadLog -> Severity |
traceAfterThread :: Tracer m AfterThreadLog -> Either SomeException a -> m () Source #
Trace an
AfterThreadLog
message from a caught exception.