🐛 Fix email sending.

This commit is contained in:
Andrey Antukh 2020-02-05 12:51:55 +01:00
parent 460019e01b
commit b4790c89ce
4 changed files with 26 additions and 14 deletions

View file

@ -102,6 +102,13 @@
(cond-> row
props (assoc :props (blob/decode props)))))
(defn- log-error
[item err]
(log/error "Unhandled exception on task '" (:name item)
"' (retry:" (:retry-num item) ") \n"
(with-out-str
(.printStackTrace ^Throwable err (java.io.PrintWriter. *out*)))))
(defn- event-loop
[{:keys [tasks] :as options}]
(let [queue (:queue options "default")
@ -114,9 +121,11 @@
(-> (p/do! (handle-task tasks item))
(p/handle (fn [v e]
(if e
(if (>= (:retry-num item) max-retries)
(mark-as-failed conn item e)
(reschedule conn item e))
(do
(log-error item e)
(if (>= (:retry-num item) max-retries)
(mark-as-failed conn item e)
(reschedule conn item e)))
(mark-as-completed conn item))))
(p/then' (constantly ::handled))))))))))

View file

@ -13,6 +13,7 @@
[clojure.tools.logging :as log]
[cuerdas.core :as str]
[postal.core :as postal]
[vertx.core :as vc]
[promesa.core :as p]
[uxbox.common.exceptions :as ex]
[uxbox.config :as cfg]
@ -48,16 +49,16 @@
(defn send-email
[email]
(p/future
(let [config (get-smtp-config cfg/config)
result (if (:enabled config)
(postal/send-message config email)
(send-email-to-console email))]
(when (not= (:error result) :SUCCESS)
(ex/raise :type :sendmail-error
:code :email-not-sent
:context result))
nil)))
(vc/blocking
(let [config (get-smtp-config cfg/config)
result (if (:enabled config)
(postal/send-message config email)
(send-email-to-console email))]
(when (not= (:error result) :SUCCESS)
(ex/raise :type :sendmail-error
:code :email-not-sent
:context result))
nil)))
(defn handler
{:uxbox.tasks/name "sendmail"}