Last active
August 29, 2015 14:22
-
-
Save avescodes/4ca2ff1e2d36ffe03749 to your computer and use it in GitHub Desktop.
Conveying Information with Simulant’s Process State Service
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns my-suite.actions.acquirer | |
(:require ;; … | |
[io.homegrown.sim-ephemeral :as eph]) | |
(defn create-payment | |
“Create a payment, returning a vector of [<response> <payment id> <nsecs taken>]” | |
[action] | |
…) | |
(defn approve-paymenet | |
“Approve a payment, returning a vector of [<response> <nsecs taken>]” | |
[id action] | |
…) | |
(defmethod sim/perform-action :action.type/createPayment [action process] | |
(try | |
(let [agent (-> action :agent/_actions solo) | |
[resp id nsecs] (create-payment action)] | |
;; Store the current payment-id for later use. | |
(store agent :payment-id :db.cardinality/one :db.type/string id) | |
(log action process resp nsecs)) | |
(catch Throwable t | |
(log-error action process t 0)))) | |
(defmethod sim/perform-action :action.type/approvePayment [action process] | |
(try | |
(let [agent (-> action :agent/_actions solo) | |
;; Retrieve the current payment-id. | |
payment-id (retrieve agent :payment-id) | |
[resp nsecs] (approve-payment payment-id action)] | |
;; At this point, it may be prudent to clear the agent’s state. | |
(clear agent) | |
(log action process resp nsecs)) | |
(catch Throwable t | |
(log-error action process t 0)))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns my-suite.sim | |
(:require ;; … | |
[simulant.sim :as sim])) | |
;; … | |
(defn- setup-sim [context] | |
;; <Extract information from context to create sim> | |
(sim/create-process-state conn sim) | |
(assoc context :sim sim)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment