|
29 | 29 | :step-result step-result}]
|
30 | 30 | (event-bus/publish!! ctx :step-result-updated payload)))
|
31 | 31 |
|
32 |
| -(defn process-channel-result-async [c {step-id :step-id build-number :build-number :as ctx}] |
| 32 | +(defn- append-result [cur-result [key value]] |
| 33 | + (-> cur-result |
| 34 | + (assoc key value) |
| 35 | + (attach-wait-indicator-if-necessary key value))) |
| 36 | + |
| 37 | +(defn- process-channel-result-async [c {step-id :step-id build-number :build-number :as ctx}] |
33 | 38 | (async/go-loop [cur-result {:status :running}]
|
34 |
| - (let [[key value] (async/<! c) |
35 |
| - new-result (-> cur-result |
36 |
| - (assoc key value) |
37 |
| - (attach-wait-indicator-if-necessary key value))] |
38 |
| - (if (and (nil? key) (nil? value)) |
| 39 | + (let [ev (async/<! c) |
| 40 | + new-result (if (map? ev) |
| 41 | + ev |
| 42 | + (append-result cur-result ev))] |
| 43 | + (if (nil? ev) |
39 | 44 | cur-result
|
40 | 45 | (do
|
41 | 46 | (event-bus/publish! ctx :step-result-updated {:build-number build-number
|
|
140 | 145 | (step-output step-id complete-step-result)))
|
141 | 146 |
|
142 | 147 | (defn merge-two-step-results [r1 r2]
|
143 |
| - (step-results/merge-step-results r1 r2 :resolvers [step-results/status-resolver |
144 |
| - step-results/merge-nested-maps-resolver |
145 |
| - step-results/combine-to-list-resolver |
146 |
| - step-results/second-wins-resolver])) |
| 148 | + (step-results/merge-two-step-results r1 r2 :resolvers [step-results/status-resolver |
| 149 | + step-results/merge-nested-maps-resolver |
| 150 | + step-results/combine-to-list-resolver |
| 151 | + step-results/second-wins-resolver])) |
147 | 152 |
|
148 | 153 | (defn- to-context-and-step [ctx]
|
149 | 154 | (fn [idx step]
|
|
152 | 157 | step-ctx (assoc ctx :step-id new-step-id)]
|
153 | 158 | [step-ctx step])))
|
154 | 159 |
|
155 |
| -(defn- process-inheritance [step-results-channel unify-status-fn] |
| 160 | +(defn- process-inheritance [step-results-channel unify-results-fn] |
156 | 161 | (let [out-ch (async/chan)]
|
157 | 162 | (async/go
|
158 |
| - (loop [statuses {}] |
159 |
| - (if-let [step-result-update (async/<! step-results-channel)] |
160 |
| - (let [step-status (get-in step-result-update [:step-result :status]) |
161 |
| - new-statuses (assoc statuses (:step-id step-result-update) step-status) |
162 |
| - old-unified (unify-status-fn (vals statuses)) |
163 |
| - new-unified (unify-status-fn (vals new-statuses))] |
| 163 | + (loop [results {}] |
| 164 | + (if-let [{step-id :step-id |
| 165 | + step-result :step-result} (async/<! step-results-channel)] |
| 166 | + (let [new-results (assoc results step-id step-result) |
| 167 | + old-unified (unify-results-fn results) |
| 168 | + new-unified (unify-results-fn new-results)] |
164 | 169 | (if (not= old-unified new-unified)
|
165 |
| - (async/>! out-ch [:status new-unified])) |
166 |
| - (recur new-statuses)) |
| 170 | + (async/>! out-ch new-unified)) |
| 171 | + (recur new-results)) |
167 | 172 | (async/close! out-ch))))
|
168 | 173 | out-ch))
|
169 | 174 |
|
|
184 | 189 | args-with-old-and-new-globals))
|
185 | 190 |
|
186 | 191 |
|
187 |
| -(defn- keep-original-args [old-args step-result] |
| 192 | +(defn keep-original-args [old-args step-result] |
188 | 193 | (merge old-args step-result))
|
189 | 194 |
|
190 |
| -(defn- serial-step-result-producer [args s-with-id] |
191 |
| - (loop [result () |
192 |
| - remaining-steps-with-id s-with-id |
193 |
| - cur-args args] |
194 |
| - (if (empty? remaining-steps-with-id) |
195 |
| - result |
196 |
| - (let [ctx-and-step (first remaining-steps-with-id) |
197 |
| - step-result (execute-step cur-args ctx-and-step) |
198 |
| - step-output (first (vals (:outputs step-result))) |
199 |
| - new-result (cons step-result result) |
200 |
| - new-args (->> step-output |
201 |
| - (keep-globals cur-args) |
202 |
| - (keep-original-args args))] |
203 |
| - (if (not= :success (:status step-result)) |
204 |
| - new-result |
205 |
| - (recur (cons step-result result) (rest remaining-steps-with-id) new-args)))))) |
| 195 | +(defn not-success? [step-result] |
| 196 | + (not= :success (:status step-result))) |
| 197 | + |
| 198 | +(defn serial-step-result-producer [& {:keys [stop-predicate] |
| 199 | + :or {stop-predicate not-success?}}] |
| 200 | + (fn [args s-with-id] |
| 201 | + (loop [result () |
| 202 | + remaining-steps-with-id s-with-id |
| 203 | + cur-args args] |
| 204 | + (if (empty? remaining-steps-with-id) |
| 205 | + result |
| 206 | + (let [ctx-and-step (first remaining-steps-with-id) |
| 207 | + step-result (execute-step cur-args ctx-and-step) |
| 208 | + step-output (first (vals (:outputs step-result))) |
| 209 | + new-result (cons step-result result) |
| 210 | + new-args (->> step-output |
| 211 | + (keep-globals cur-args) |
| 212 | + (keep-original-args args))] |
| 213 | + (if (stop-predicate step-result) |
| 214 | + new-result |
| 215 | + (recur (cons step-result result) (rest remaining-steps-with-id) new-args))))))) |
206 | 216 |
|
207 | 217 | (defn- inherit-message-from-parent? [parent-ctx]
|
208 | 218 | (fn [msg]
|
|
259 | 269 |
|
260 | 270 | (def not-nil? (complement nil?))
|
261 | 271 |
|
262 |
| -(defn execute-steps [steps args ctx & {:keys [step-result-producer is-killed unify-status-fn retrigger-predicate] |
263 |
| - :or {step-result-producer serial-step-result-producer |
| 272 | +(defn unify-only-status [unify-status-fn] |
| 273 | + (fn [step-results] |
| 274 | + {:status (unify-status-fn (->> step-results |
| 275 | + (vals) |
| 276 | + (map :status)))})) |
| 277 | + |
| 278 | +(defn execute-steps [steps args ctx & {:keys [step-result-producer is-killed unify-status-fn unify-results-fn retrigger-predicate] |
| 279 | + :or {step-result-producer (serial-step-result-producer) |
264 | 280 | is-killed (atom false)
|
265 | 281 | unify-status-fn status/successful-when-all-successful
|
| 282 | + unify-results-fn nil ; dependent on unify-status-fn, can't have it here for now |
266 | 283 | retrigger-predicate sequential-retrigger-predicate}}]
|
267 |
| - (let [steps (filter not-nil? steps) |
| 284 | + (let [unify-results-fn (or unify-results-fn (unify-only-status unify-status-fn)) |
| 285 | + steps (filter not-nil? steps) |
268 | 286 | base-ctx-with-kill-switch (assoc ctx :is-killed is-killed)
|
269 | 287 | subscription (event-bus/subscribe ctx :step-result-updated)
|
270 | 288 | children-step-results-channel (->> subscription
|
271 | 289 | (event-bus/only-payload)
|
272 | 290 | (async/filter< (inherit-message-from-parent? ctx)))
|
273 | 291 | step-contexts (contexts-for-steps steps base-ctx-with-kill-switch)
|
274 |
| - _ (inherit-from children-step-results-channel (:result-channel ctx) unify-status-fn) |
| 292 | + _ (inherit-from children-step-results-channel (:result-channel ctx) unify-results-fn) |
275 | 293 | step-contexts-with-retrigger-mocks (add-retrigger-mocks retrigger-predicate ctx step-contexts)
|
276 | 294 | step-results (step-result-producer args step-contexts-with-retrigger-mocks)
|
277 | 295 | result (reduce merge-two-step-results step-results)]
|
|
0 commit comments