This repository has been archived by the owner on Jun 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wait for pipelines to complete when killing all pipelines (#103)
- Loading branch information
Showing
7 changed files
with
94 additions
and
13 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
(ns lambdacd.internal.running-builds-tracking | ||
(:require [lambdacd.event-bus :as event-bus] | ||
[clojure.core.async :as async])) | ||
|
||
(defn running-step-record [payload] | ||
{:step-id (:step-id payload) | ||
:build-number (:build-number payload)}) | ||
|
||
(defn initialize-running-builds-tracking [ctx] | ||
(let [steps-started-subscription (event-bus/subscribe ctx :step-started) | ||
steps-started-payload (event-bus/only-payload steps-started-subscription) | ||
|
||
steps-finished-subscription (event-bus/subscribe ctx :step-finished) | ||
steps-finished-payload (event-bus/only-payload steps-finished-subscription) | ||
started-steps (atom #{})] | ||
(async/go-loop [] | ||
(if-let [payload (async/<! steps-started-payload)] | ||
(do | ||
(swap! started-steps #(conj % (running-step-record payload))) | ||
(recur)))) | ||
(async/go-loop [] | ||
(if-let [payload (async/<! steps-finished-payload)] | ||
(do | ||
(swap! started-steps #(disj % (running-step-record payload))) | ||
(recur)))) | ||
(assoc ctx :started-steps started-steps))) |
This file contains 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
This file contains 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
23 changes: 23 additions & 0 deletions
23
test/clj/lambdacd/internal/running_builds_tracking_test.clj
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
(ns lambdacd.internal.running-builds-tracking-test | ||
(:require [clojure.test :refer :all] | ||
[lambdacd.internal.running-builds-tracking :refer :all] | ||
[lambdacd.testsupport.data :refer [some-ctx some-ctx-with]] | ||
[lambdacd.testsupport.test-util :refer [wait-for]] | ||
[lambdacd.event-bus :as event-bus])) | ||
|
||
(deftest running-builds-tracker | ||
(testing "that it adds running builds and step-ids when steps start runnning and removes them if they stop" | ||
(let [ctx (initialize-running-builds-tracking (some-ctx))] | ||
|
||
(event-bus/publish ctx :step-started {:step-id [1] :build-number 1}) | ||
(event-bus/publish ctx :step-started {:step-id [2 2] :build-number 2}) | ||
|
||
(wait-for (= 2 (count @(:started-steps ctx)))) | ||
(is (= #{{:step-id [1] :build-number 1} | ||
{:step-id [2 2] :build-number 2}} @(:started-steps ctx))) | ||
|
||
(event-bus/publish ctx :step-finished {:step-id [2 2] :build-number 2 :final-result {:foo :bar}}) | ||
|
||
(wait-for (= 1 (count @(:started-steps ctx)))) | ||
|
||
(is (= #{{:step-id [1] :build-number 1}} @(:started-steps ctx)))))) |
This file contains 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