Skip to content

Instantly share code, notes, and snippets.

@avescodes
Last active August 29, 2015 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save avescodes/4ca2ff1e2d36ffe03749 to your computer and use it in GitHub Desktop.
Save avescodes/4ca2ff1e2d36ffe03749 to your computer and use it in GitHub Desktop.
Conveying Information with Simulant’s Process State Service
(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))))
(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