mirror of
https://github.com/penpot/penpot.git
synced 2025-05-11 09:26:36 +02:00
✨ Improve tasks-gc task
This commit is contained in:
parent
5867e64d36
commit
8d7baa75de
1 changed files with 23 additions and 10 deletions
|
@ -8,7 +8,9 @@
|
||||||
"A maintenance task that performs a cleanup of already executed tasks
|
"A maintenance task that performs a cleanup of already executed tasks
|
||||||
from the database table."
|
from the database table."
|
||||||
(:require
|
(:require
|
||||||
|
[app.common.data :as d]
|
||||||
[app.common.logging :as l]
|
[app.common.logging :as l]
|
||||||
|
[app.config :as cf]
|
||||||
[app.db :as db]
|
[app.db :as db]
|
||||||
[app.util.time :as dt]
|
[app.util.time :as dt]
|
||||||
[clojure.spec.alpha :as s]
|
[clojure.spec.alpha :as s]
|
||||||
|
@ -16,20 +18,31 @@
|
||||||
|
|
||||||
(declare sql:delete-completed-tasks)
|
(declare sql:delete-completed-tasks)
|
||||||
|
|
||||||
(s/def ::max-age ::dt/duration)
|
(s/def ::min-age ::dt/duration)
|
||||||
|
|
||||||
(defmethod ig/pre-init-spec ::handler [_]
|
(defmethod ig/pre-init-spec ::handler [_]
|
||||||
(s/keys :req-un [::db/pool ::max-age]))
|
(s/keys :req-un [::db/pool]
|
||||||
|
:opt-un [::min-age]))
|
||||||
|
|
||||||
|
(defmethod ig/prep-key ::handler
|
||||||
|
[_ cfg]
|
||||||
|
(merge {:min-age cf/deletion-delay}
|
||||||
|
(d/without-nils cfg)))
|
||||||
|
|
||||||
(defmethod ig/init-key ::handler
|
(defmethod ig/init-key ::handler
|
||||||
[_ {:keys [pool max-age] :as cfg}]
|
[_ {:keys [pool] :as cfg}]
|
||||||
(fn [_]
|
(fn [params]
|
||||||
(db/with-atomic [conn pool]
|
(let [min-age (or (:min-age params) (:min-age cfg))]
|
||||||
(let [interval (db/interval max-age)
|
(db/with-atomic [conn pool]
|
||||||
result (db/exec-one! conn [sql:delete-completed-tasks interval])
|
(let [interval (db/interval min-age)
|
||||||
result (:next.jdbc/update-count result)]
|
result (db/exec-one! conn [sql:delete-completed-tasks interval])
|
||||||
(l/debug :hint "trim completed tasks table" :removed result)
|
result (:next.jdbc/update-count result)]
|
||||||
result))))
|
(l/debug :hint "task finished" :total result)
|
||||||
|
|
||||||
|
(when (:rollback? params)
|
||||||
|
(db/rollback! conn))
|
||||||
|
|
||||||
|
result)))))
|
||||||
|
|
||||||
(def ^:private
|
(def ^:private
|
||||||
sql:delete-completed-tasks
|
sql:delete-completed-tasks
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue