From 43b3019e8180824ad8795eac202444b064034cb4 Mon Sep 17 00:00:00 2001 From: Ruben Bartelink Date: Thu, 13 Feb 2020 16:48:13 +0000 Subject: [PATCH] tmp --- equinox-fc/Domain/Domain.fsproj | 2 +- equinox-fc/Domain/InventoryTransaction.fs | 26 +++++++++++++---------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/equinox-fc/Domain/Domain.fsproj b/equinox-fc/Domain/Domain.fsproj index 472c3527b..1ac6eac73 100644 --- a/equinox-fc/Domain/Domain.fsproj +++ b/equinox-fc/Domain/Domain.fsproj @@ -15,7 +15,7 @@ - + diff --git a/equinox-fc/Domain/InventoryTransaction.fs b/equinox-fc/Domain/InventoryTransaction.fs index 1fd4c03c3..0c2bc1482 100644 --- a/equinox-fc/Domain/InventoryTransaction.fs +++ b/equinox-fc/Domain/InventoryTransaction.fs @@ -1,3 +1,12 @@ +/// Process Manager used to: +/// - Coordinate competing attempts to transfer quantities from stock; if balance is 3 one of contesting requests to remove 2 or 3 items must reach `Failed` +/// - maintain rolling balance of stock levels per Location +/// - while recording any transfers or adjustment in an overall Inventory record +/// The Process is driven by two actors: +/// 1) The 'happy path', where a given actor is executing the known steps of the command flow +/// In the normal case, such an actor will bring the flow to a terminal state (Completed or Failed) +/// 2) A watchdog-projector, which reacts to observed events in this Category by stepping in to complete in-flight requests that have stalled +/// This represents the case where a 'happy path' actor died, or experienced another impediment on the path. module Fc.InventoryTransaction open System @@ -6,14 +15,13 @@ open System [] module Events = - let [] CategoryId = "Transfer" - let (|For|) (inventoryId, transactionId) = - FsCodec.StreamName.compose CategoryId [InventoryId.toString inventoryId; InventoryTransactionId.toString transactionId] + let [] CategoryId = "InventoryTransfer" + let (|For|) (inventoryId, transactionId) = FsCodec.StreamName.create CategoryId (InventoryTransactionId.toString transactionId) + type AdjustmentRequested = { location : LocationId; quantity : int } type TransferRequested = { source : LocationId; destination : LocationId; quantity : int } type Removed = { balance : int } type Added = { balance : int } - type AdjustmentRequested = { location : LocationId; quantity : int } type Event = | AdjustmentRequested of AdjustmentRequested @@ -59,13 +67,9 @@ module Fold = | Events.Completed -> Completed let fold : State -> Events.Event seq -> State = Seq.fold evolve -type Result = - { /// Indicates whether this epoch is closed (either previously or as a side-effect this time) - isClosed : bool - /// Count of items added to this epoch. May be less than requested due to removal of duplicates and/or rejected items - added : int - /// residual items that [are not duplicates and] were not accepted into this epoch - rejected : Events.Event list } +type Command = + | Adjust of Events.AdjustmentRequested + | Transfer of Events.TransferRequested let decideSync capacity requested (state : Fold.State) : Result * Events.Event list = let isFresh = function