mirror of
https://github.com/penpot/penpot.git
synced 2025-06-12 13:41:38 +02:00
✨ Make the task retry algorithm use better backoff values
This commit is contained in:
parent
d3347a1be0
commit
9bfdcc6277
2 changed files with 19 additions and 18 deletions
|
@ -266,7 +266,7 @@
|
||||||
(wrk/submit! (assoc email
|
(wrk/submit! (assoc email
|
||||||
::wrk/task :sendmail
|
::wrk/task :sendmail
|
||||||
::wrk/delay 0
|
::wrk/delay 0
|
||||||
::wrk/max-retries 1
|
::wrk/max-retries 4
|
||||||
::wrk/priority 200
|
::wrk/priority 200
|
||||||
::wrk/conn conn))))
|
::wrk/conn conn))))
|
||||||
|
|
||||||
|
|
|
@ -270,11 +270,6 @@
|
||||||
(s/keys :req [::task ::conn]
|
(s/keys :req [::task ::conn]
|
||||||
:opt [::delay ::queue ::priority ::max-retries]))
|
:opt [::delay ::queue ::priority ::max-retries]))
|
||||||
|
|
||||||
(def ^:private sql:insert-new-task
|
|
||||||
"insert into task (id, name, props, queue, priority, max_retries, scheduled_at)
|
|
||||||
values (?, ?, ?, ?, ?, ?, clock_timestamp() + ?)
|
|
||||||
returning id")
|
|
||||||
|
|
||||||
(defn- extract-props
|
(defn- extract-props
|
||||||
[options]
|
[options]
|
||||||
(persistent!
|
(persistent!
|
||||||
|
@ -285,6 +280,11 @@
|
||||||
(transient {})
|
(transient {})
|
||||||
options)))
|
options)))
|
||||||
|
|
||||||
|
(def ^:private sql:insert-new-task
|
||||||
|
"insert into task (id, name, props, queue, priority, max_retries, scheduled_at)
|
||||||
|
values (?, ?, ?, ?, ?, ?, now() + ?)
|
||||||
|
returning id")
|
||||||
|
|
||||||
(defn submit!
|
(defn submit!
|
||||||
[{:keys [::task ::delay ::queue ::priority ::max-retries ::conn]
|
[{:keys [::task ::delay ::queue ::priority ::max-retries ::conn]
|
||||||
:or {delay 0 queue :default priority 100 max-retries 3}
|
:or {delay 0 queue :default priority 100 max-retries 3}
|
||||||
|
@ -294,10 +294,13 @@
|
||||||
interval (db/interval duration)
|
interval (db/interval duration)
|
||||||
props (-> options extract-props db/tjson)
|
props (-> options extract-props db/tjson)
|
||||||
id (uuid/next)]
|
id (uuid/next)]
|
||||||
|
|
||||||
(l/debug :action "submit task"
|
(l/debug :action "submit task"
|
||||||
:name (d/name task)
|
:name (d/name task)
|
||||||
:in duration)
|
:in duration)
|
||||||
(db/exec-one! conn [sql:insert-new-task id (d/name task) props (d/name queue) priority max-retries interval])
|
|
||||||
|
(db/exec-one! conn [sql:insert-new-task id (d/name task) props
|
||||||
|
(d/name queue) priority max-retries interval])
|
||||||
id))
|
id))
|
||||||
|
|
||||||
;; --- RUNNER
|
;; --- RUNNER
|
||||||
|
@ -305,22 +308,20 @@
|
||||||
(def ^:private
|
(def ^:private
|
||||||
sql:mark-as-retry
|
sql:mark-as-retry
|
||||||
"update task
|
"update task
|
||||||
set scheduled_at = clock_timestamp() + ?::interval,
|
set scheduled_at = now() + ?::interval,
|
||||||
modified_at = clock_timestamp(),
|
modified_at = now(),
|
||||||
error = ?,
|
error = ?,
|
||||||
status = 'retry',
|
status = 'retry',
|
||||||
retry_num = retry_num + ?
|
retry_num = ?
|
||||||
where id = ?")
|
where id = ?")
|
||||||
|
|
||||||
(def default-delay
|
|
||||||
(dt/duration {:seconds 10}))
|
|
||||||
|
|
||||||
(defn- mark-as-retry
|
(defn- mark-as-retry
|
||||||
[conn {:keys [task error inc-by delay]
|
[conn {:keys [task error inc-by delay]
|
||||||
:or {inc-by 1 delay default-delay}}]
|
:or {inc-by 1 delay 1000}}]
|
||||||
(let [explain (ex-message error)
|
(let [explain (ex-message error)
|
||||||
delay (db/interval delay)
|
nretry (+ (:retry-num task) inc-by)
|
||||||
sqlv [sql:mark-as-retry delay explain inc-by (:id task)]]
|
delay (->> (iterate #(* % 2) delay) (take nretry) (last))
|
||||||
|
sqlv [sql:mark-as-retry (db/interval delay) explain nretry (:id task)]]
|
||||||
(db/exec-one! conn sqlv)
|
(db/exec-one! conn sqlv)
|
||||||
nil))
|
nil))
|
||||||
|
|
||||||
|
@ -430,8 +431,8 @@
|
||||||
(map deref)
|
(map deref)
|
||||||
(run! (fn [res]
|
(run! (fn [res]
|
||||||
(case (:status res)
|
(case (:status res)
|
||||||
:retry (mark-as-retry conn res)
|
:retry (mark-as-retry conn res)
|
||||||
:failed (mark-as-failed conn res)
|
:failed (mark-as-failed conn res)
|
||||||
:completed (mark-as-completed conn res)))))
|
:completed (mark-as-completed conn res)))))
|
||||||
::handled)))))
|
::handled)))))
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue