From bdd00be5e42909060ef0fe514a416d07a6c1e9a9 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Thu, 15 Dec 2022 11:26:58 +0100 Subject: [PATCH] :bug: Fix incorrect deduplication of tasks on webhooks --- backend/src/app/loggers/audit.clj | 23 +++++++++++-------- backend/src/app/rpc/commands/files/update.clj | 6 +---- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/backend/src/app/loggers/audit.clj b/backend/src/app/loggers/audit.clj index 853e9709c..d400d6387 100644 --- a/backend/src/app/loggers/audit.clj +++ b/backend/src/app/loggers/audit.clj @@ -170,21 +170,24 @@ (when (and (contains? cf/flags :webhooks) (::webhooks/event? 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/task :process-webhook-event ::wrk/queue :webhooks ::wrk/max-retries 0 ::wrk/delay (or batch-timeout 0) - ::wrk/label (cond - (fn? batch-key) (batch-key (:props event)) - (keyword? batch-key) (name batch-key) - (string? batch-key) batch-key - :else "default") - ::wrk/dedupe true - ::webhooks/event (-> params - (dissoc :ip-addr) - (dissoc :type))))))) + ::wrk/dedupe dedupe? + ::wrk/label + (str/ffmt "rpc:%1%2" (:name params) label-suffix) + + ::webhooks/event + (-> params + (dissoc :ip-addr) + (dissoc :type))))))) (defn submit! "Submit audit event to the collector." diff --git a/backend/src/app/rpc/commands/files/update.clj b/backend/src/app/rpc/commands/files/update.clj index 264d29615..991dcadef 100644 --- a/backend/src/app/rpc/commands/files/update.clj +++ b/backend/src/app/rpc/commands/files/update.clj @@ -123,16 +123,12 @@ ;; set is different than the persisted one, update it on the ;; database. -(defn webhook-batch-keyfn - [props] - (str "rpc:update-file:" (:id props))) - (sv/defmethod ::update-file {::climit/queue :update-file ::climit/key-fn :id ::webhooks/event? true ::webhooks/batch-timeout (dt/duration "2m") - ::webhooks/batch-key webhook-batch-keyfn + ::webhooks/batch-key :id ::doc/added "1.17"} [{:keys [pool] :as cfg} {:keys [id profile-id] :as params}] (db/with-atomic [conn pool]