mealstrom-0.0.0.1: Manipulate FSMs and store them in PostgreSQL.

Copyright(c) Max Amanshauser 2016
LicenseMIT
Maintainermax@lambdalifting.org
Safe HaskellNone
LanguageHaskell2010

Mealstrom.FSMApi

Description

This is the interface through which you primarily interact with a FSM from the rest of your program.

Synopsis

Documentation

data FSMHandle st wal k s e a where Source #

Constructors

FSMHandle :: (Eq s, Eq e, Eq a, FSMStore st k s e a, WALStore wal k, FSMKey k) => {..} -> FSMHandle st wal k s e a 

Fields

  • fsmStore :: st

    Which backend to use for storing FSMs.

  • walStore :: wal

    Which backend to use for the WAL.

  • fsmTable :: FSMTable s e a

    A table of transitions and effects. This is not in a typeclass, because you may want to use MVars or similar in effects. See the tests for examples.

  • effTimeout :: Int

    How much time to allow for Actions until they are considered failed.

  • retryCount :: Int

    How often to automatically retry actions.

get :: forall st wal k s e a. FSMStore st k s e a => FSMHandle st wal k s e a -> k -> IO (Maybe s) Source #

post :: forall st wal k s e a. FSMStore st k s e a => FSMHandle st wal k s e a -> k -> s -> IO Bool Source #

Idempotent because of usage of caller-generated keys.

patch :: forall st wal k s e a. (FSMStore st k s e a, MealyInstance k s e a, FSMKey k) => FSMHandle st wal k s e a -> k -> [Msg e] -> IO Bool Source #

Concurrent updates will be serialised by Postgres. Returns True when the state transition has been successfully computed and actions have been scheduled. Returns False on failure.

recover :: forall st wal k s e a. (FSMStore st k s e a, MealyInstance k s e a, FSMKey k) => FSMHandle st wal k s e a -> k -> IO () Source #

Recovering is the process of asynchronously applying Actions. It is performed immediately after the synchronous part of an update and, on failure, retried until it succeeds or the retry limit is hit.

recoverAll :: forall st wal k s e a. MealyInstance k s e a => FSMHandle st wal k s e a -> IO () Source #

During certain long-lasting failures, like network outage, the retry limit of Actions will be exhausted. You should regularly, e.g. ever 10 minutes, call this function to clean up those hard cases.

upsert :: forall st wal k s e a. MealyInstance k s e a => FSMStore st k s e a => FSMHandle st wal k s e a -> k -> s -> [Msg e] -> IO () Source #

A helper that is sometimes useful