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

Commit

Permalink
allow killing all running pipelines (#103)
Browse files Browse the repository at this point in the history
  • Loading branch information
flosell committed Apr 3, 2016
1 parent 9e8e7bd commit 24f51cb
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
23 changes: 21 additions & 2 deletions src/clj/lambdacd/internal/execution.clj
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,21 @@
(finally
(async/close! (:result-channel ctx)))))

(defn- step-id-to-kill? [step-id kill-payload]
(let [step-id-to-kill (:step-id kill-payload)

exact-step-id-match (= step-id step-id-to-kill)

any-root-match (and (= :any-root step-id-to-kill)
(= 1 (count step-id)))]
(or exact-step-id-match
any-root-match)))

(defn- build-number-to-kill? [build-number kill-payload]
(let [build-number-to-kill (:build-number kill-payload)]
(or (= build-number build-number-to-kill)
(= :any build-number-to-kill))))

(defn kill-step-handling [ctx]
(let [is-killed (:is-killed ctx)
step-id (:step-id ctx)
Expand All @@ -67,8 +82,8 @@
(async/go-loop []
(if-let [kill-payload (async/<! kill-payloads)]
(if (and
(= step-id (:step-id kill-payload))
(= build-number (:build-number kill-payload)))
(step-id-to-kill? step-id kill-payload)
(build-number-to-kill? build-number kill-payload))
(do
(reset! is-killed true)
(async/>!! (:result-channel ctx) [:received-kill true]))
Expand Down Expand Up @@ -281,3 +296,7 @@
(event-bus/publish ctx :kill-step {:step-id step-id
:build-number build-number}))

(defn kill-all-pipelines [ctx]
(log/info "Killing all running pipelines...")
(event-bus/publish ctx :kill-step {:step-id :any-root
:build-number :any}))
19 changes: 18 additions & 1 deletion test/clj/lambdacd/internal/execution_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -391,4 +391,21 @@
(is (= [{:build-number 1
:step-id [1 1]
:step-result expected-child-result}]
(slurp-chan step-finished-events))))))
(slurp-chan step-finished-events))))))


(deftest kill-all-pipelines-test
(testing "that it kills root build steps in any pipeline"
(let [ctx (some-ctx-with :step-id [3])
_ (pipeline-state/start-pipeline-state-updater (:pipeline-state-component ctx) ctx)
future-step-result (start-waiting-for (execute-step {} [ctx some-step-waiting-to-be-killed]))]
(wait-for (tu/step-running? ctx))
(kill-all-pipelines ctx)
(is (map-containing {:status :killed} (get-or-timeout future-step-result :timeout 1000)))))
(testing "that it doesn't kill nested steps as they are killed by their parents"
(let [ctx (some-ctx-with :step-id [3 1])
_ (pipeline-state/start-pipeline-state-updater (:pipeline-state-component ctx) ctx)
future-step-result (start-waiting-for (execute-step {} [ctx some-step-waiting-to-be-killed]))]
(wait-for (tu/step-running? ctx))
(kill-all-pipelines ctx)
(is (map-containing {:status :timeout} (get-or-timeout future-step-result :timeout 1000))))))

0 comments on commit 24f51cb

Please sign in to comment.