mirror of
https://github.com/penpot/penpot.git
synced 2025-05-11 14:36:37 +02:00
Merge pull request #3554 from penpot/niwinz-staging-bugfixes-8
🐛 Prevent rollback for idle-in-transaction errors on cron tasks
This commit is contained in:
commit
b0497f1352
3 changed files with 14 additions and 6 deletions
|
@ -15,7 +15,7 @@ export PENPOT_FLAGS="\
|
||||||
enable-fdata-storage-objets-map \
|
enable-fdata-storage-objets-map \
|
||||||
disable-secure-session-cookies \
|
disable-secure-session-cookies \
|
||||||
enable-smtp \
|
enable-smtp \
|
||||||
enable-webhooks";
|
enable-access-tokens";
|
||||||
|
|
||||||
set -ex
|
set -ex
|
||||||
|
|
||||||
|
|
|
@ -81,7 +81,7 @@
|
||||||
(let [explain (ex/explain data)]
|
(let [explain (ex/explain data)]
|
||||||
{::yrs/status 400
|
{::yrs/status 400
|
||||||
::yrs/body (-> data
|
::yrs/body (-> data
|
||||||
(dissoc ::s/problems ::s/value)
|
(dissoc ::s/problems ::s/value ::s/spec)
|
||||||
(cond-> explain (assoc :explain explain)))})
|
(cond-> explain (assoc :explain explain)))})
|
||||||
|
|
||||||
(= code :params-validation)
|
(= code :params-validation)
|
||||||
|
|
|
@ -574,8 +574,11 @@
|
||||||
(l/trace :hint "register cron task" :id id :cron (str cron))
|
(l/trace :hint "register cron task" :id id :cron (str cron))
|
||||||
(db/exec-one! conn [sql:upsert-cron-task id (str cron) (str cron)]))))
|
(db/exec-one! conn [sql:upsert-cron-task id (str cron) (str cron)]))))
|
||||||
|
|
||||||
(def sql:lock-cron-task
|
(defn- lock-scheduled-task!
|
||||||
"select id from scheduled_task where id=? for update skip locked")
|
[conn id]
|
||||||
|
(let [sql (str "SELECT id FROM scheduled_task "
|
||||||
|
" WHERE id=? FOR UPDATE SKIP LOCKED")]
|
||||||
|
(some? (db/exec-one! conn [sql (d/name id)]))))
|
||||||
|
|
||||||
(defn- execute-cron-task
|
(defn- execute-cron-task
|
||||||
[{:keys [::db/pool] :as cfg} {:keys [id] :as task}]
|
[{:keys [::db/pool] :as cfg} {:keys [id] :as task}]
|
||||||
|
@ -583,11 +586,16 @@
|
||||||
{:name (str "penpot/cront-task/" id)}
|
{:name (str "penpot/cront-task/" id)}
|
||||||
(try
|
(try
|
||||||
(db/with-atomic [conn pool]
|
(db/with-atomic [conn pool]
|
||||||
(when (db/exec-one! conn [sql:lock-cron-task (d/name id)])
|
(db/exec-one! conn ["SET statement_timeout=0;"])
|
||||||
|
(db/exec-one! conn ["SET idle_in_transaction_session_timeout=0;"])
|
||||||
|
(when (lock-scheduled-task! conn id)
|
||||||
(l/trace :hint "cron: execute task" :task-id id)
|
(l/trace :hint "cron: execute task" :task-id id)
|
||||||
((:fn task) task)))
|
((:fn task) task))
|
||||||
|
(db/rollback! conn))
|
||||||
|
|
||||||
(catch InterruptedException _
|
(catch InterruptedException _
|
||||||
(l/debug :hint "cron: task interrupted" :task-id id))
|
(l/debug :hint "cron: task interrupted" :task-id id))
|
||||||
|
|
||||||
(catch Throwable cause
|
(catch Throwable cause
|
||||||
(binding [l/*context* (get-error-context cause task)]
|
(binding [l/*context* (get-error-context cause task)]
|
||||||
(l/error :hint "cron: unhandled exception on running task"
|
(l/error :hint "cron: unhandled exception on running task"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue