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:
Teemu Patja 2017-03-06 12:51:03 +02:00
parent 22d1fcc517
commit b69a6f5728
No known key found for this signature in database
GPG Key ID: F5B7035E6580FD4C
2 changed files with 12 additions and 4 deletions

View File

@ -12,7 +12,7 @@
[commiteth.util.digest :refer [hex-hmac-sha1]]
[compojure.core :refer [defroutes POST]]
[crypto.equality :as crypto]
[ring.util.http-response :refer [ok]]
[ring.util.http-response :refer [ok forbidden]]
[commiteth.db.bounties :as bounties-db])
(:import java.lang.Integer))
@ -194,8 +194,10 @@
(defroutes webhook-routes
(POST "/webhook" {:keys [headers body]}
(log/debug "webhook POST, headers" headers)
(let [raw-payload (slurp body)
payload (json/parse-string raw-payload true)]
(log/debug "webhook POST, payload" payload)
(if (validate-secret payload raw-payload (get headers "x-hub-signature"))
(do
(log/debug "Github secret validation OK")
@ -203,4 +205,5 @@
(case (get headers "x-github-event")
"issues" (handle-issue payload)
"pull_request" (handle-pull-request payload)
(ok)))))))
(ok)))
(forbidden)))))

View File

@ -134,14 +134,19 @@
(update-confirm-hash)
(update-payout-receipt)
(self-sign-bounty)
(update-balances)))
(update-balances)
(log/debug "run-periodic-tasks done")))
(mount/defstate scheduler
:start (let [every-minute (rest
(periodic-seq (t/now)
(-> 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")
stop-fn)
:stop (do