From cf4f999b6a0ecf3fd846ff6d3059677ded6dd11d Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Fri, 11 Mar 2022 09:50:49 +0100 Subject: [PATCH] :paperclip: Improve api ergonomy of http server module --- backend/src/app/http.clj | 19 +++++++++++-------- backend/src/app/main.clj | 2 +- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/backend/src/app/http.clj b/backend/src/app/http.clj index ccca990fa..2b59de492 100644 --- a/backend/src/app/http.clj +++ b/backend/src/app/http.clj @@ -35,8 +35,8 @@ (s/def ::port ::us/integer) (s/def ::host ::us/string) (s/def ::name ::us/string) -(s/def ::executors (s/map-of keyword? ::wrk/executor)) (s/def ::io-threads ::cf/http-server-io-threads) +(s/def ::worker-threads integer?) (defmethod ig/prep-key ::server [_ cfg] @@ -46,18 +46,21 @@ (d/without-nils cfg))) (defmethod ig/pre-init-spec ::server [_] - (s/keys :req-un [::port ::host ::name ::executors] - :opt-un [::router ::handler ::io-threads])) + (s/keys :req-un [::port ::host ::name] + :opt-un [::router ::handler ::io-threads ::worker-threads ::wrk/executor])) (defmethod ig/init-key ::server - [_ {:keys [handler router port name host executors] :as cfg}] + [_ {:keys [handler router port name host executor io-threads worker-threads] :as cfg}] (l/info :hint "starting http server" :port port :host host :name name) - (let [options {:http/port port - :http/host host - :ring/async true - :xnio/dispatch (:default executors)} + (let [options (d/without-nils + {:http/port port + :http/host host + :ring/async true + :xnio/io-threads io-threads + :xnio/worker-threads worker-threads + :xnio/dispatch executor}) handler (cond (fn? handler) handler (some? router) (wrap-router cfg router) diff --git a/backend/src/app/main.clj b/backend/src/app/main.clj index a361c2eda..ec0808a8c 100644 --- a/backend/src/app/main.clj +++ b/backend/src/app/main.clj @@ -113,7 +113,7 @@ :host (cf/get :http-server-host) :router (ig/ref :app.http/router) :metrics (ig/ref :app.metrics/metrics) - :executors (ig/ref :app.worker/executors) + :executor (ig/ref [::default :app.worker/executor]) :io-threads (cf/get :http-server-io-threads)} :app.http/router