Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
klauswuestefeld committed May 21, 2024
1 parent 7b43b89 commit e510dc4
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/prevayler_clj_aws/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
{state :state previous-snapshot-index :partkey} (read-snapshot s3-client s3-bucket snapshot-path)
_ (println "Reading snapshot bucket done.")
state-atom (atom (or state initial-state))
snapshot-index (inc previous-snapshot-index)
snapshot-index-atom (atom (inc previous-snapshot-index))
order-atom (atom 0)]

(println "Restoring events...")
Expand All @@ -122,7 +122,7 @@

; since s3 update is atomic, if saving snapshot fails next prevayler will pick the previous state
; and restore events from the previous partkey
(save-snapshot! s3-client s3-bucket snapshot-path {:state @state-atom :partkey snapshot-index})
(save-snapshot! s3-client s3-bucket snapshot-path {:state @state-atom :partkey @snapshot-index-atom})
(println "Saving snapshot done.")

(reify
Expand All @@ -133,7 +133,7 @@
timestamp (timestamp-fn)
new-state (business-fn current-state event timestamp)] ; (C)onsistency: must be guaranteed by the handler. The event won't be journalled when the handler throws an exception.)
(when-not (identical? new-state current-state)
(write-event! dynamodb-client dynamodb-table snapshot-index
(write-event! dynamodb-client dynamodb-table @snapshot-index-atom
(swap! order-atom inc) ; Skips an order number if there is an exception, but that's OK.
[timestamp event (hash new-state)]) ; (D)urability
(reset! state-atom new-state)) ; (A)tomicity
Expand Down

0 comments on commit e510dc4

Please sign in to comment.