From 995017df5acd783f2d5300037938f8aecf0cbc86 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Mon, 22 Feb 2021 12:48:21 +0100 Subject: [PATCH] :tada: Add the ability to execute code on the end of http request. Mainly for register metrics once the main transaction is commited. --- backend/src/app/rpc.clj | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/backend/src/app/rpc.clj b/backend/src/app/rpc.clj index e768315f2..7f7237dad 100644 --- a/backend/src/app/rpc.clj +++ b/backend/src/app/rpc.clj @@ -25,6 +25,11 @@ [_] (ex/raise :type :not-found)) +(defn- run-hook + [hook-fn response] + (ex/ignoring (hook-fn)) + response) + (defn- rpc-query-handler [methods {:keys [profile-id] :as request}] (let [type (keyword (get-in request [:path-params :type])) @@ -50,7 +55,11 @@ result ((get methods type default-handler) data) mdata (meta result)] (cond->> {:status 200 :body result} - (fn? (:transform-response mdata)) ((:transform-response mdata) request)))) + (fn? (:transform-response mdata)) + ((:transform-response mdata) request) + + (fn? (:before-complete mdata)) + (run-hook (:before-complete mdata))))) (defn- wrap-with-metrics [cfg f mdata]