Commit graph

30 commits

Author SHA1 Message Date
Vincent Ambo
b748117225 feat(postgres): Introduce database connection pool
Adds an r2d2 database connection pool to the backend type. This makes
it possible for separate FSMs to run at the same time through the same
backend, by retrieving separate connections.
2018-12-13 16:53:54 +01:00
Vincent Ambo
42d56713bd fix(door): Ensure compatibility with updated FSM trait 2018-12-13 15:08:26 +01:00
Vincent Ambo
e801b5853c feat(postgres): Add human-readable Display implementation for errors 2018-12-13 15:01:05 +01:00
Vincent Ambo
68060fea13 feat(postgres): Introduce chained error variants
Introduces error variants for external crate errors and internal
errors.

Additional context can be provided at sites where errors occur using a
simple `.context()` call.
2018-12-13 14:40:59 +01:00
Vincent Ambo
43f71ae82f refactor(postgres): Implement FSMBackend trait for FinitoPostgres
Implements the new backend trait for the FinitoPostgres type which
now represents instances of the Postgres backend.

This refactoring is not yet fully complete, as some restructuring of
the code is in order.
2018-12-13 13:40:54 +01:00
Vincent Ambo
183ee2accc fix(core): Ensure FSM state can be created from backend state ref
The action interpreter can not own the backend state, hence it must be
possible to create the required state from a reference to the
backend's state.
2018-12-13 13:39:16 +01:00
Vincent Ambo
1a90856ba4 feat(core): Add serde trait bounds to FSM types
These are required by multiple backend implementations, and any
attempt at making them optional will result in less appreciable APIs.
2018-12-13 12:24:41 +01:00
Vincent Ambo
536793dbbb fix(door): Update trait impl with State type
The door does not actually require any state, so it just uses an empty
tuple.
2018-11-22 16:59:42 +01:00
Vincent Ambo
8c5ab60ac3 chore: Fix email address in Cargo files 2018-11-19 13:51:14 +01:00
Vincent Ambo
6ff56f860b feat(core): Add a trait representing backend implementations
First version of a trait to abstract over backend implementations.

Currently the different backends still have a bit of specific
behaviour, but it should be possible to boil this down to a single
trait.

The primary question that is still open is how to best deal with the
interpretation of actions, as it is sort of up to the backend to
decide how to do that.
2018-10-24 08:50:53 +02:00
Vincent Ambo
45afa18846 feat(postgres): Compatibility with new associated error type
Changes the implementation of action execution to deal with the
returned associated errors.

The only sensible constraint on those errors that I could think of for
now is `Debug`, meaning that errors are now persisted as debug
messages.

This is not as nice to work with for a future implementation of
retryable actions as the equivalent in Haskell, but maybe an idea
shows up underway. The main issue is that most of the common error
types will not be implementing Serde traits, so serialization to/from
the same error type is difficult.

Adding an implementation constraint for JSON serialisation on error
types (i.e. `S::Error: Serialize + Deserialize`) would probably cause
headaches for users, especially if they are trying to use an
out-of-the-box error type or an error type wrapping foreign errors.

Det ska'kke være lett ...
2018-09-26 23:19:34 +02:00
Vincent Ambo
c4b94d8d2d feat(door): Use failure::Error as associated error type
Implements the associated error type for the FSM trait as
failure::Error. This makes it possible to fail gracefully in all
actions, for example in the updated definition of the `NotifyIRC`
action which now appends to a file.
2018-09-26 23:18:26 +02:00
Vincent Ambo
37590ae0f6 feat(core): Add associated 'Error' type to FSM trait
Adds an associated 'Error' type that can be returned by actions when
an interpretation fails.
2018-09-26 23:05:50 +02:00
Vincent Ambo
406a90e8d6 feat(postgres): Implement initial (synchronous) actoin execution
Implements a simple model for executing actions which will run them in
sequence, synchronously, after advancing an FSM and committing the
initial transaction.

Note that multiple things are not yet taken into account:

* Error handling of actions (they can not currently fail)
* Retrying of actions
* Concurrency model

I started out by implementing the concurrency model similarly to the
green-threading method used in Hamingja (but using OS threads), but
slowly noticed that it may not be the best way to do that. It needs a
little bit of discussion.

Either way for most actions this method is fast enough to work for
implementing things on top of Finito's model.
2018-09-26 22:31:42 +02:00
Vincent Ambo
3891ba84d5 test(postgres): Add test for insert_machine and advance
Adds a test for the two most important functions in Finito's
PostgreSQL backend.

These actually require a local Postgres database to be available when
running. Currently the connection details are hardcoded in the test.
2018-09-26 18:44:16 +02:00
Vincent Ambo
7e5592f0d1 fix(postgres): Minor fixes in Postgres queries and handling 2018-09-26 18:43:53 +02:00
Vincent Ambo
6254d05620 feat(door): Add serde instances for door FSM types 2018-09-26 18:43:24 +02:00
Vincent Ambo
6e35c083bf refactor(postgres): Minor changes to match actual table schema 2018-09-26 18:20:04 +02:00
Vincent Ambo
cbb58fa6c2 feat(postgres): Add initial table schema for Finito tables 2018-09-26 18:19:10 +02:00
Vincent Ambo
fe97c712cc docs: Add rustdoc header lines as expected by the format
These are rendered in the rustdoc crate overview sidebar.
2018-09-26 18:04:28 +02:00
Vincent Ambo
965574913e docs(core): Fix rustdoc syntax in several places 2018-09-26 18:02:55 +02:00
Vincent Ambo
401486d124 docs(door): Port over documentation from finito-hs 2018-09-26 18:00:41 +02:00
Vincent Ambo
40caa5ffa2 feat(postgres): Implement Postgres-backed 'advance' function
Transactionally updates a state machine with an incoming event. Note
that this does not yet interpret actions.
2018-09-26 17:28:45 +02:00
Vincent Ambo
b1e00ff026 feat(postgres): Bootstrap Postgres persistence implementation
Adds the initial finito-postgres crate with type definitions for the
tables and initial functions to interact with persisted FSMs.

This is far from feature complete at this commit.
2018-09-26 16:54:06 +02:00
Vincent Ambo
c03e14758f fix(core): Add missing 'FSM_NAME' associated constant
This one got lost while moving from the prototype code to the proper
library.
2018-09-26 16:54:06 +02:00
Vincent Ambo
60824a06f1 feat(door): Check in example door implementation
Checks in my classic, lockable door example implemented in Finito.

This does not yet contain the documentation of the door in the Haskell
version of Finito.
2018-09-26 16:54:03 +02:00
Vincent Ambo
da66599696 feat(core): Check in Finito core library
The implementation of this library is closely modeled after the core
abstraction in the Haskell library. This does not at all concern
itself with persistence, interpretation of effects and so on.
2018-09-26 16:54:00 +02:00
Vincent Ambo
6d11928efe docs: Add initial README 2018-09-26 11:34:08 +02:00
Vincent Ambo
bc873b9666 chore: Add Rust-specific .gitignore file 2018-09-26 11:33:52 +02:00
Vincent Ambo
f8ae63c2da chore: Initial commit 2018-09-26 11:29:48 +02:00