Skip to content
This repository has been archived by the owner on Mar 22, 2023. It is now read-only.

Commit

Permalink
provide custom-components to composite scheduler service-id->schedule…
Browse files Browse the repository at this point in the history
…r-fn (#1564)
  • Loading branch information
DaoWen authored May 4, 2022
1 parent cd67f5a commit d6092f3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
5 changes: 3 additions & 2 deletions waiter/src/waiter/scheduler/composite.clj
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@

(defn create-composite-scheduler
"Creates and starts composite scheduler with components using their respective factory functions."
[{:keys [default-scheduler scheduler-state-chan selector-context service-id->service-description-fn]
[{:keys [custom-components default-scheduler scheduler-state-chan selector-context service-id->service-description-fn]
:or {selector-context {}}
:as config}]
(let [scheduler-id->component (initialize-component-schedulers config)
Expand All @@ -283,7 +283,8 @@
'waiter.scheduler.composite/create-scheduler-parameter-based-selector)
create-selector-fn (utils/resolve-symbol! create-selector-sym)
service-id->scheduler-fn (create-selector-fn
(merge {:default-scheduler default-scheduler
(merge {:custom-components custom-components
:default-scheduler default-scheduler
:scheduler-id->scheduler scheduler-id->scheduler
:service-id->service-description-fn service-id->service-description-fn}
(dissoc selector-context :factory-fn)))
Expand Down
14 changes: 14 additions & 0 deletions waiter/test/waiter/scheduler/composite_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@
:ipsum {:factory-fn 'waiter.scheduler.composite-test/create-test-scheduler
:scheduler-name "ipsum"
:service-ids ["ipsum-fee" "ipsum-foo" "ipsum-fuu"]}}
:custom-components {:foo {:bar :baz}}
:default-scheduler default-scheduler
:scheduler-state-chan scheduler-state-chan
:service-id->password-fn service-id->password-fn
Expand All @@ -302,6 +303,19 @@
(is composite-scheduler)
(is (fn? (:query-aggregator-state-fn composite-scheduler)))))

(testing "provides custom-components to service-id->scheduler-fn"
(let [provided-context-atom (atom nil)]
(with-redefs [create-some-image-parameter-based-selector
(fn [context] (reset! provided-context-atom context))]
(let [scheduler-config (assoc scheduler-config
:selector-context {:factory-fn 'waiter.scheduler.composite/create-some-image-parameter-based-selector
:image-scheduler :ipsum})
composite-scheduler (create-composite-scheduler scheduler-config)]
(is (some? composite-scheduler))
(is (some? @provided-context-atom))
(is (= (:custom-components scheduler-config)
(:custom-components @provided-context-atom)))))))

(testing "using scheduler-parameter selector context"
(let [old-create-scheduler-parameter-based-selector create-scheduler-parameter-based-selector
function-called-atom (atom nil)]
Expand Down

0 comments on commit d6092f3

Please sign in to comment.