Skip to content

Commit

Permalink
rename core/run-execution to start-executiong add . to denote blockin…
Browse files Browse the repository at this point in the history
…g call, naming like core.async
  • Loading branch information
Quantisan committed May 3, 2021
1 parent 52d9edf commit f6b9524
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 39 deletions.
18 changes: 9 additions & 9 deletions README.md
Expand Up @@ -40,7 +40,7 @@ At the REPL:
(stepwise/start-workers {:activity/add (fn [{:keys [x y]}] (+ x y))})
=> ...

(stepwise/run-execution :adder {:input {:x 1 :y 1}})
(stepwise/start-execution!! :adder {:input {:x 1 :y 1}})
=>
{:input {:x 1 :y 1}
:output 2
Expand All @@ -57,18 +57,18 @@ At the REPL:

## Development Workflow

Stepwise enables a rapidly cycling development workflow for Step Functions. State machine definition updates are eventually consistent, so new state machines need to be created on each cycle during development. Also, activity task polls are long and cannot be interrupted, demanding registration of new activities (or a JVM restart) to prevent stealing by stale bytecode. Stepwise provides a single function, `stepwise.reloaded/run-execution`, that uses fresh state machine and activity task registrations to run a state machine execution wherein code changes are immediately reflected.
Stepwise enables a rapidly cycling development workflow for Step Functions. State machine definition updates are eventually consistent, so new state machines need to be created on each cycle during development. Also, activity task polls are long and cannot be interrupted, demanding registration of new activities (or a JVM restart) to prevent stealing by stale bytecode. Stepwise provides a single function, `stepwise.reloaded/start-execution!!`, that uses fresh state machine and activity task registrations to run a state machine execution wherein code changes are immediately reflected.

Example:

```clojure
(stepwise.reloaded/run-execution :adder
{:start-at :add
:states {:add {:type :task
:resource :activity/add
:end true}}}
{:activity/add (fn [{:keys [x y]}] (+ x y))}
{:x 41 :y 1})
(stepwise.reloaded/start-execution!! :adder
{:start-at :add
:states {:add {:type :task
:resource :activity/add
:end true}}}
{:activity/add (fn [{:keys [x y]}] (+ x y))}
{:x 41 :y 1})
=>
{:output 42,
:state-machine-arn "arn:aws:states:us-west-2:256212633204:stateMachine:adder-1522697821734",
Expand Down
10 changes: 5 additions & 5 deletions src/stepwise/core.clj
Expand Up @@ -39,9 +39,9 @@
(activities/resolve-resources arns/resource-arn->kw)
(denamespace-keys)))

(defn start-execution
(defn start-execution!
([state-machine-name]
(start-execution state-machine-name nil))
(start-execution! state-machine-name nil))
([state-machine-name {:keys [input execution-name]}]
; TODO always include these(?)
(let [input (if execution-name
Expand All @@ -66,11 +66,11 @@
(recur (client/describe-execution execution-arn)))
(denamespace-keys execution))))

(defn run-execution
(defn start-execution!!
([state-machine-name]
(run-execution state-machine-name nil))
(start-execution!! state-machine-name nil))
([state-machine-name {:keys [input execution-name] :as opts}]
(await-execution (start-execution state-machine-name opts))))
(await-execution (start-execution! state-machine-name opts))))

(defn start-workers
([task-handlers]
Expand Down
8 changes: 4 additions & 4 deletions src/stepwise/reloaded.clj
Expand Up @@ -22,7 +22,7 @@
(name activity-name))]))
activity-names))

(defn run-execution [machine-name definition task-handlers input]
(defn start-execution!! [machine-name definition task-handlers input]
(let [snapshot-name (machine-name->snapshot machine-name)
activity-names (activities/get-names definition)
activity->snapshot (activity-name->snapshot snapshot-name activity-names)
Expand All @@ -31,9 +31,9 @@
snapshot-arn (core/ensure-state-machine snapshot-name definition)
workers (core/start-workers (sets/rename-keys task-handlers
activity->snapshot))
result (core/run-execution snapshot-name
{:input input
:execution-name (str (UUID/randomUUID))})]
result (core/start-execution!! snapshot-name
{:input input
:execution-name (str (UUID/randomUUID))})]
(core/kill-workers workers)
(doseq [[_ snapshot-name] activity->snapshot]
(client/delete-activity (arns/get-activity-arn snapshot-name)))
Expand Down
42 changes: 21 additions & 21 deletions test/stepwise/dev_repl.clj
Expand Up @@ -39,13 +39,13 @@
(mdl/map->StateMachine)))

(defn sandbox []
(reloaded/run-execution :adder
{:start-at :add
:states {:add {:type :task
:resource :activity/add
:end true}}}
{:activity/add (fn [{:keys [x y]}] (+ x y))}
{:x 41 :y 1})
(reloaded/start-execution!! :adder
{:start-at :add
:states {:add {:type :task
:resource :activity/add
:end true}}}
{:activity/add (fn [{:keys [x y]}] (+ x y))}
{:x 41 :y 1})

#_(s/explain-data ::sgr/state-machine
{:start-at :my-choice
Expand Down Expand Up @@ -100,10 +100,10 @@
:timeout-seconds 3
:end true}}})

(stepwise/run-execution namespace
machine-id
{:input {:a 1
:b 2}})
(stepwise/start-execution!! namespace
machine-id
{:input {:a 1
:b 2}})
(stepwise/shutdown-workers workers)
)

Expand All @@ -115,16 +115,16 @@
; :timeout-seconds 3
; :end true}}})

#_(reloaded/run-execution "ncgl-dev-dacc"
:test-machine-v2
{:start-at :do-the-sum
:states {:do-the-sum {:type :task
:resource :sum
:timeout-seconds 180
:end true}}}
{:sum (fn [{:keys [a b]}] (+ a b))}
{:a 1
:b 2})
#_(reloaded/start-execution!! "ncgl-dev-dacc"
:test-machine-v2
{:start-at :do-the-sum
:states {:do-the-sum {:type :task
:resource :sum
:timeout-seconds 180
:end true}}}
{:sum (fn [{:keys [a b]}] (+ a b))}
{:a 1
:b 2})
#_(sgr/get-non-model-keys {:foo [{:bar :bam}]
:bim {:boom :bap
::mdl/resource "hi"}})
Expand Down

0 comments on commit f6b9524

Please sign in to comment.