0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-24 15:39:50 -05:00

🐛 Fix incorrect deduplication of tasks on webhooks

This commit is contained in:
Andrey Antukh 2022-12-15 11:26:58 +01:00
parent 6eedb5315b
commit bdd00be5e4
2 changed files with 14 additions and 15 deletions

View file

@ -170,21 +170,24 @@
(when (and (contains? cf/flags :webhooks) (when (and (contains? cf/flags :webhooks)
(::webhooks/event? event)) (::webhooks/event? event))
(let [batch-key (::webhooks/batch-key event) (let [batch-key (::webhooks/batch-key event)
batch-timeout (::webhooks/batch-timeout event)] batch-timeout (::webhooks/batch-timeout event)
label-suffix (when (ifn? batch-key)
(str/ffmt ":%" (batch-key (:props params))))
dedupe? (boolean
(and batch-key batch-timeout))]
(wrk/submit! ::wrk/conn pool (wrk/submit! ::wrk/conn pool
::wrk/task :process-webhook-event ::wrk/task :process-webhook-event
::wrk/queue :webhooks ::wrk/queue :webhooks
::wrk/max-retries 0 ::wrk/max-retries 0
::wrk/delay (or batch-timeout 0) ::wrk/delay (or batch-timeout 0)
::wrk/label (cond ::wrk/dedupe dedupe?
(fn? batch-key) (batch-key (:props event)) ::wrk/label
(keyword? batch-key) (name batch-key) (str/ffmt "rpc:%1%2" (:name params) label-suffix)
(string? batch-key) batch-key
:else "default") ::webhooks/event
::wrk/dedupe true (-> params
::webhooks/event (-> params (dissoc :ip-addr)
(dissoc :ip-addr) (dissoc :type)))))))
(dissoc :type)))))))
(defn submit! (defn submit!
"Submit audit event to the collector." "Submit audit event to the collector."

View file

@ -123,16 +123,12 @@
;; set is different than the persisted one, update it on the ;; set is different than the persisted one, update it on the
;; database. ;; database.
(defn webhook-batch-keyfn
[props]
(str "rpc:update-file:" (:id props)))
(sv/defmethod ::update-file (sv/defmethod ::update-file
{::climit/queue :update-file {::climit/queue :update-file
::climit/key-fn :id ::climit/key-fn :id
::webhooks/event? true ::webhooks/event? true
::webhooks/batch-timeout (dt/duration "2m") ::webhooks/batch-timeout (dt/duration "2m")
::webhooks/batch-key webhook-batch-keyfn ::webhooks/batch-key :id
::doc/added "1.17"} ::doc/added "1.17"}
[{:keys [pool] :as cfg} {:keys [id profile-id] :as params}] [{:keys [pool] :as cfg} {:keys [id profile-id] :as params}]
(db/with-atomic [conn pool] (db/with-atomic [conn pool]