Scheduler logging fix & fix 500 error for unexpected webhook
* log exception in case scheduled task fails * return 403 response in case validating webhook POST secret fails * add logging
This commit is contained in:
parent
22d1fcc517
commit
b69a6f5728
|
@ -12,7 +12,7 @@
|
||||||
[commiteth.util.digest :refer [hex-hmac-sha1]]
|
[commiteth.util.digest :refer [hex-hmac-sha1]]
|
||||||
[compojure.core :refer [defroutes POST]]
|
[compojure.core :refer [defroutes POST]]
|
||||||
[crypto.equality :as crypto]
|
[crypto.equality :as crypto]
|
||||||
[ring.util.http-response :refer [ok]]
|
[ring.util.http-response :refer [ok forbidden]]
|
||||||
[commiteth.db.bounties :as bounties-db])
|
[commiteth.db.bounties :as bounties-db])
|
||||||
(:import java.lang.Integer))
|
(:import java.lang.Integer))
|
||||||
|
|
||||||
|
@ -194,8 +194,10 @@
|
||||||
|
|
||||||
(defroutes webhook-routes
|
(defroutes webhook-routes
|
||||||
(POST "/webhook" {:keys [headers body]}
|
(POST "/webhook" {:keys [headers body]}
|
||||||
|
(log/debug "webhook POST, headers" headers)
|
||||||
(let [raw-payload (slurp body)
|
(let [raw-payload (slurp body)
|
||||||
payload (json/parse-string raw-payload true)]
|
payload (json/parse-string raw-payload true)]
|
||||||
|
(log/debug "webhook POST, payload" payload)
|
||||||
(if (validate-secret payload raw-payload (get headers "x-hub-signature"))
|
(if (validate-secret payload raw-payload (get headers "x-hub-signature"))
|
||||||
(do
|
(do
|
||||||
(log/debug "Github secret validation OK")
|
(log/debug "Github secret validation OK")
|
||||||
|
@ -203,4 +205,5 @@
|
||||||
(case (get headers "x-github-event")
|
(case (get headers "x-github-event")
|
||||||
"issues" (handle-issue payload)
|
"issues" (handle-issue payload)
|
||||||
"pull_request" (handle-pull-request payload)
|
"pull_request" (handle-pull-request payload)
|
||||||
(ok)))))))
|
(ok)))
|
||||||
|
(forbidden)))))
|
||||||
|
|
|
@ -134,14 +134,19 @@
|
||||||
(update-confirm-hash)
|
(update-confirm-hash)
|
||||||
(update-payout-receipt)
|
(update-payout-receipt)
|
||||||
(self-sign-bounty)
|
(self-sign-bounty)
|
||||||
(update-balances)))
|
(update-balances)
|
||||||
|
(log/debug "run-periodic-tasks done")))
|
||||||
|
|
||||||
|
|
||||||
(mount/defstate scheduler
|
(mount/defstate scheduler
|
||||||
:start (let [every-minute (rest
|
:start (let [every-minute (rest
|
||||||
(periodic-seq (t/now)
|
(periodic-seq (t/now)
|
||||||
(-> 1 t/minutes)))
|
(-> 1 t/minutes)))
|
||||||
stop-fn (chime-at every-minute run-periodic-tasks)]
|
stop-fn (chime-at every-minute
|
||||||
|
run-periodic-tasks
|
||||||
|
{:error-handler (fn [e]
|
||||||
|
(log/error "Scheduled task failed" e)
|
||||||
|
(throw e))})]
|
||||||
(log/info "started scheduler")
|
(log/info "started scheduler")
|
||||||
stop-fn)
|
stop-fn)
|
||||||
:stop (do
|
:stop (do
|
||||||
|
|
Loading…
Reference in New Issue