Skip to content
This repository has been archived by the owner on Jun 15, 2024. It is now read-only.

Commit

Permalink
Merge pull request #32 from redvox/issue-28-add-junction
Browse files Browse the repository at this point in the history
Add junction to control flow.  Fixes #28.
  • Loading branch information
flosell committed Jul 9, 2015
2 parents 1849d55 + 0337c8c commit 3d978e0
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/clj/lambdacd/internal/execution.clj
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
(defn- to-context-and-step [ctx step-results-channel]
(fn [idx step]
(let [parent-step-id (:step-id ctx)
new-step-id (cons (inc idx) parent-step-id)
new-step-id (step-id/child-id parent-step-id (inc idx))
step-ctx (assoc ctx :step-id new-step-id
:step-results-channel step-results-channel)]
[step-ctx step])))
Expand Down Expand Up @@ -221,4 +221,4 @@
(let [next-build-number (pipeline-state/next-build-number (:pipeline-state-component context))]
(async/thread
(retrigger pipeline context build-number step-id-to-run next-build-number ))
next-build-number))
next-build-number))
5 changes: 4 additions & 1 deletion src/clj/lambdacd/internal/step_id.clj
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,7 @@
(defn before? [a b]
(and
(not (= a b))
(not (later-than? a b))))
(not (later-than? a b))))

(defn child-id [parent-step-id child-number]
(cons child-number parent-step-id))
13 changes: 12 additions & 1 deletion src/clj/lambdacd/steps/control_flow.clj
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
(:require [lambdacd.core :as core]
[clojure.core.async :as async]
[lambdacd.steps.support :as support]
[lambdacd.internal.step-id :as step-id]
[lambdacd.steps.status :as status]))

(defn- post-process-container-results [result]
Expand Down Expand Up @@ -59,4 +60,14 @@
(fn [args ctx]
(post-process-container-results
(core/execute-steps steps args ctx
:unify-status-fn status/successful-when-all-successful))))
:unify-status-fn status/successful-when-all-successful))))

(defn- child-context [ctx child-number]
(assoc ctx :step-id (step-id/child-id (:step-id ctx) child-number)))

(defn ^{:display-type :parallel} junction [condition-step success-step failiure-step]
(fn [args ctx]
(post-process-container-results
(if (= :success (:status (core/execute-step args [(child-context ctx 1) condition-step])))
(core/execute-step args [(child-context ctx 2) success-step])
(core/execute-step args [(child-context ctx 3) failiure-step])))))
14 changes: 14 additions & 0 deletions test/clj/lambdacd/steps/control_flow_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@
(defn some-step-that-returns-42 [args ctx]
{:status :success :the-number 42})

(defn some-step-that-returns-foo [args ctx]
{:status :success :message :foo})

(defn some-step-that-returns-bar [args ctx]
{:status :success :message :bar})

(deftest in-parallel-test
(testing "that it collects all the outputs together correctly"
(is (map-containing {:outputs { [1 0 0] {:foo :baz :status :undefined} [2 0 0] {:foo :baz :status :undefined}} :status :undefined} ((in-parallel some-step some-step) {} (some-ctx-with :step-id [0 0])))))
Expand Down Expand Up @@ -110,3 +116,11 @@
(is (= [[:status :running]
[:status :waiting]
[:status :success]] (slurp-chan result-ch))))))

(deftest junction-test
(testing "that it executes the success-step if the condition is a success"
(is (map-containing {:outputs {[2 0 0] {:status :success :message :foo}}}
((junction some-successful-step some-step-that-returns-foo some-step-that-returns-bar) {} (some-ctx-with :step-id [0 0])))))
(testing "that it executes the success-step if the condition is a success"
(is (map-containing {:outputs {[3 0 0] {:status :success :message :bar}}}
((junction some-failing-step some-step-that-returns-foo some-step-that-returns-bar) {} (some-ctx-with :step-id [0 0]))))))

0 comments on commit 3d978e0

Please sign in to comment.