Skip to content

Commit

Permalink
feat: log more details when sending event notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
opqdonut committed Apr 20, 2020
1 parent 425e04b commit 9604f5d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
9 changes: 4 additions & 5 deletions src/clj/rems/event_notification.clj
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@
(def ^:private default-timeout 60)

(defn- notify! [target body]
(log/info "Sending event notification to" (:url target))
(log/info "Sending event notification for event" (select-keys body [:application/id :event/type :event/time])
"to" (:url target))
(try
(let [timeout-ms (* 1000 (get target :timeout default-timeout))
response (http/put (getx target :url)
{:body body
{:body (json/generate-string body)
:throw-exceptions false
:content-type :json
:headers (get target :headers)
Expand Down Expand Up @@ -68,9 +69,7 @@
(is (true? (wants? target {:event/type :application.event/approved})))))

(defn- notification-body [event]
(-> event
(assoc :event/application (applications/get-application (:application/id event)))
json/generate-string))
(assoc event :event/application (applications/get-application (:application/id event))))

(defn queue-notifications! [events]
(when-let [targets (seq (get rems.config/env :event-notification-targets))]
Expand Down
7 changes: 4 additions & 3 deletions test/clj/rems/test_event_notification.clj
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
(with-open [server (stub/start! {"/ok" {:status 200}
"/broken" {:status 500}
"/timeout" {:status 200 :delay 5000}})]
(let [body "body"]
(let [body {:value 1}]
(testing "success"
(is (nil? (#'event-notification/notify! {:url (str (:uri server) "/ok")
:headers {"additional-header" "value"}}
Expand All @@ -29,9 +29,10 @@
(is (empty? more))
(is (= {:method "PUT"
:path "/ok"
:body {"content" body}}
:body {"content" (json/generate-string body)}}
(select-keys req [:method :path :body])))
(is (= "value" (get-in req [:headers :additional-header])))))
(is (= "value" (get-in req [:headers :additional-header])))
))
(testing "error code"
(is (= "failed: 500" (#'event-notification/notify! {:url (str (:uri server) "/broken")}
body))))
Expand Down

0 comments on commit 9604f5d

Please sign in to comment.