mirror of
https://github.com/penpot/penpot.git
synced 2025-07-30 10:28:22 +02:00
🐛 Fix incorrect task result handling
That caused that many task rows in a table not properly marked as completed and leaved just as scheduled.
This commit is contained in:
parent
6a87d5eea9
commit
210e5b0023
2 changed files with 57 additions and 19 deletions
|
@ -40,7 +40,9 @@
|
||||||
- Fix problem with constraints when creating group [Taiga #10455](https://tree.taiga.io/project/penpot/issue/10455)
|
- Fix problem with constraints when creating group [Taiga #10455](https://tree.taiga.io/project/penpot/issue/10455)
|
||||||
- Fix opening pen with shortcut multiple times breaks toolbar [Taiga #10566](https://tree.taiga.io/project/penpot/issue/10566)
|
- Fix opening pen with shortcut multiple times breaks toolbar [Taiga #10566](https://tree.taiga.io/project/penpot/issue/10566)
|
||||||
- Fix actions when workspace is visited first time [Taiga #10548](https://tree.taiga.io/project/penpot/issue/10548)
|
- Fix actions when workspace is visited first time [Taiga #10548](https://tree.taiga.io/project/penpot/issue/10548)
|
||||||
- Chat icon overlaps "Show" button in carrousel section [Taiga #10542](https://tree.taiga.io/project/penpot/issue/10542)
|
- Fix chat icon overlaps "Show" button in carrousel section [Taiga #10542](https://tree.taiga.io/project/penpot/issue/10542)
|
||||||
|
- Fix incorrect handling of background task result (now task rows are properly marked as completed)
|
||||||
|
|
||||||
|
|
||||||
## 2.5.4
|
## 2.5.4
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,33 @@
|
||||||
|
|
||||||
(set! *warn-on-reflection* true)
|
(set! *warn-on-reflection* true)
|
||||||
|
|
||||||
|
(def schema:task
|
||||||
|
[:map {:title "Task"}
|
||||||
|
[:id ::sm/uuid]
|
||||||
|
[:queue :string]
|
||||||
|
[:name :string]
|
||||||
|
[:created-at ::sm/inst]
|
||||||
|
[:modified-at ::sm/inst]
|
||||||
|
[:scheduled-at {:optional true} ::sm/inst]
|
||||||
|
[:completed-at {:optional true} ::sm/inst]
|
||||||
|
[:error {:optional true} :string]
|
||||||
|
[:max-retries :int]
|
||||||
|
[:retry-num :int]
|
||||||
|
[:priority :int]
|
||||||
|
[:status [:enum "scheduled" "completed" "new" "retry" "failed"]]
|
||||||
|
[:label {:optional true} :string]
|
||||||
|
[:props :map]])
|
||||||
|
|
||||||
|
(def schema:result
|
||||||
|
[:map {:title "TaskResult"}
|
||||||
|
[:status [:enum "retry" "failed" "completed"]]
|
||||||
|
[:error {:optional true} [:fn ex/exception?]]
|
||||||
|
[:inc-by {:optional true} :int]
|
||||||
|
[:delay {:optional true} :int]])
|
||||||
|
|
||||||
|
(def valid-task-result?
|
||||||
|
(sm/validator schema:result))
|
||||||
|
|
||||||
(defn- decode-task-row
|
(defn- decode-task-row
|
||||||
[{:keys [props] :as row}]
|
[{:keys [props] :as row}]
|
||||||
(cond-> row
|
(cond-> row
|
||||||
|
@ -51,10 +78,11 @@
|
||||||
:retry (:retry-num task))
|
:retry (:retry-num task))
|
||||||
(let [tpoint (dt/tpoint)
|
(let [tpoint (dt/tpoint)
|
||||||
task-fn (wrk/get-task registry (:name task))
|
task-fn (wrk/get-task registry (:name task))
|
||||||
result (if task-fn
|
result (when task-fn (task-fn task))
|
||||||
(task-fn task)
|
elapsed (dt/format-duration (tpoint))
|
||||||
{:status :completed :task task})
|
result (if (valid-task-result? result)
|
||||||
elapsed (dt/format-duration (tpoint))]
|
result
|
||||||
|
{:status "completed"})]
|
||||||
|
|
||||||
(when-not task-fn
|
(when-not task-fn
|
||||||
(l/wrn :hint "no task handler found" :name (:name task)))
|
(l/wrn :hint "no task handler found" :name (:name task)))
|
||||||
|
@ -76,7 +104,7 @@
|
||||||
(if (and (< (:retry-num task)
|
(if (and (< (:retry-num task)
|
||||||
(:max-retries task))
|
(:max-retries task))
|
||||||
(= ::retry (:type edata)))
|
(= ::retry (:type edata)))
|
||||||
(cond-> {:status :retry :task task :error cause}
|
(cond-> {:status "retry" :error cause}
|
||||||
(dt/duration? (:delay edata))
|
(dt/duration? (:delay edata))
|
||||||
(assoc :delay (:delay edata))
|
(assoc :delay (:delay edata))
|
||||||
|
|
||||||
|
@ -87,8 +115,8 @@
|
||||||
::l/context (get-error-context cause task)
|
::l/context (get-error-context cause task)
|
||||||
:cause cause)
|
:cause cause)
|
||||||
(if (>= (:retry-num task) (:max-retries task))
|
(if (>= (:retry-num task) (:max-retries task))
|
||||||
{:status :failed :task task :error cause}
|
{:status "failed" :error cause}
|
||||||
{:status :retry :task task :error cause})))))))
|
{:status "retry" :error cause})))))))
|
||||||
|
|
||||||
(defn- run-task!
|
(defn- run-task!
|
||||||
[{:keys [::id ::timeout] :as cfg} task-id]
|
[{:keys [::id ::timeout] :as cfg} task-id]
|
||||||
|
@ -116,12 +144,17 @@
|
||||||
:task-id task-id)
|
:task-id task-id)
|
||||||
|
|
||||||
:else
|
:else
|
||||||
(run-task cfg task))))
|
(let [result (run-task cfg task)]
|
||||||
|
(with-meta result
|
||||||
|
{::task task})))))
|
||||||
|
|
||||||
(defn- run-worker-loop!
|
(defn- run-worker-loop!
|
||||||
[{:keys [::db/pool ::rds/rconn ::timeout ::queue] :as cfg}]
|
[{:keys [::db/pool ::rds/rconn ::timeout ::queue] :as cfg}]
|
||||||
(letfn [(handle-task-retry [{:keys [task error inc-by delay] :or {inc-by 1 delay 1000}}]
|
(letfn [(handle-task-retry [{:keys [error inc-by delay] :or {inc-by 1 delay 1000} :as result}]
|
||||||
(let [explain (ex-message error)
|
(let [explain (if (ex/exception? error)
|
||||||
|
(ex-message error)
|
||||||
|
(str error))
|
||||||
|
task (-> result meta ::task)
|
||||||
nretry (+ (:retry-num task) inc-by)
|
nretry (+ (:retry-num task) inc-by)
|
||||||
now (dt/now)
|
now (dt/now)
|
||||||
delay (->> (iterate #(* % 2) delay) (take nretry) (last))]
|
delay (->> (iterate #(* % 2) delay) (take nretry) (last))]
|
||||||
|
@ -134,8 +167,9 @@
|
||||||
{:id (:id task)})
|
{:id (:id task)})
|
||||||
nil))
|
nil))
|
||||||
|
|
||||||
(handle-task-failure [{:keys [task error]}]
|
(handle-task-failure [{:keys [error] :as result}]
|
||||||
(let [explain (ex-message error)]
|
(let [task (-> result meta ::task)
|
||||||
|
explain (ex-message error)]
|
||||||
(db/update! pool :task
|
(db/update! pool :task
|
||||||
{:error explain
|
{:error explain
|
||||||
:modified-at (dt/now)
|
:modified-at (dt/now)
|
||||||
|
@ -143,8 +177,9 @@
|
||||||
{:id (:id task)})
|
{:id (:id task)})
|
||||||
nil))
|
nil))
|
||||||
|
|
||||||
(handle-task-completion [{:keys [task]}]
|
(handle-task-completion [result]
|
||||||
(let [now (dt/now)]
|
(let [task (-> result meta ::task)
|
||||||
|
now (dt/now)]
|
||||||
(db/update! pool :task
|
(db/update! pool :task
|
||||||
{:completed-at now
|
{:completed-at now
|
||||||
:modified-at now
|
:modified-at now
|
||||||
|
@ -168,10 +203,11 @@
|
||||||
(process-result [{:keys [status] :as result}]
|
(process-result [{:keys [status] :as result}]
|
||||||
(ex/try!
|
(ex/try!
|
||||||
(case status
|
(case status
|
||||||
:retry (handle-task-retry result)
|
"retry" (handle-task-retry result)
|
||||||
:failed (handle-task-failure result)
|
"failed" (handle-task-failure result)
|
||||||
:completed (handle-task-completion result)
|
"completed" (handle-task-completion result)
|
||||||
nil)))
|
(throw (IllegalArgumentException.
|
||||||
|
(str "invalid status received: " status))))))
|
||||||
|
|
||||||
(run-task-loop [task-id]
|
(run-task-loop [task-id]
|
||||||
(loop [result (run-task! cfg task-id)]
|
(loop [result (run-task! cfg task-id)]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue