mirror of
https://github.com/penpot/penpot.git
synced 2025-05-11 06:26:38 +02:00
🐛 Fix many bugs in email sending namespaces.
This commit is contained in:
parent
e7db88a647
commit
d546d1fdca
6 changed files with 66 additions and 18 deletions
|
@ -29,8 +29,7 @@
|
|||
[email context]
|
||||
(let [defaults {:from (:email-from cfg/config)
|
||||
:reply-to (:email-reply-to cfg/config)}]
|
||||
(->> (email context)
|
||||
(merge defaults))))
|
||||
(email (merge defaults context))))
|
||||
|
||||
(defn send!
|
||||
"Schedule the email for sending."
|
||||
|
@ -39,8 +38,8 @@
|
|||
(s/assert map? context)
|
||||
(let [defaults {:from (:email-from cfg/config)
|
||||
:reply-to (:email-reply-to cfg/config)}
|
||||
data (->> (email context)
|
||||
(merge defaults)
|
||||
data (->> (merge defaults context)
|
||||
(email)
|
||||
(blob/encode))
|
||||
priority (case (:priority context :high) :low 1 :high 10)
|
||||
sql "insert into email_queue (data, priority)
|
||||
|
|
|
@ -53,8 +53,7 @@
|
|||
[conn id]
|
||||
(let [sql "update email_queue
|
||||
set status = 'ok'
|
||||
where id = $1
|
||||
and deleted_at is null;"]
|
||||
where id = $1"]
|
||||
(-> (db/query-one conn [sql id])
|
||||
(p/then (constantly nil)))))
|
||||
|
||||
|
@ -111,11 +110,13 @@
|
|||
(defn send-email
|
||||
[conn {:keys [id data] :as entry}]
|
||||
(-> (impl-sendmail data)
|
||||
(p/then (fn [_]
|
||||
(mark-email-as-sent conn id)))
|
||||
(p/catch (fn [e]
|
||||
(log/error e "Error on sending email" id)
|
||||
(mark-email-as-failed conn id)))))
|
||||
(p/handle (fn [v e]
|
||||
(if e
|
||||
(do
|
||||
(log/error e "Error on sending email" id)
|
||||
(mark-email-as-failed conn id))
|
||||
(mark-email-as-sent conn id))))))
|
||||
|
||||
|
||||
;; --- Main Task Functions
|
||||
|
||||
|
@ -123,7 +124,8 @@
|
|||
[opts]
|
||||
(db/with-atomic [conn db/pool]
|
||||
(p/let [items (fetch-emails conn)]
|
||||
(p/run! (partial send-email conn) items))))
|
||||
(-> (p/run! (partial send-email conn) items)
|
||||
(p/then' (constantly (count items)))))))
|
||||
|
||||
(defn send-failed-emails
|
||||
[opts]
|
||||
|
|
|
@ -115,11 +115,13 @@
|
|||
(defn- impl-query
|
||||
[conn sql params {:keys [xfm] :as opts}]
|
||||
(let [conn (if (instance? IDeref conn) @conn conn)]
|
||||
(->> (impl-execute conn sql params)
|
||||
(p/map (fn [rows]
|
||||
(if xfm
|
||||
(into [] xfm rows)
|
||||
(into [] (map vec) rows)))))))
|
||||
(-> (impl-execute conn sql params)
|
||||
(p/catch' (fn [err]
|
||||
(p/rejected err)))
|
||||
(p/then' (fn [rows]
|
||||
(if xfm
|
||||
(into [] xfm rows)
|
||||
(into [] (map vec) rows)))))))
|
||||
|
||||
(defn impl-transact
|
||||
[pool f]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue