mirror of
https://github.com/penpot/penpot.git
synced 2025-01-10 08:50:57 -05:00
✨ Improve file-xlog-gc task
This commit is contained in:
parent
ac8ef1d622
commit
df00760ffa
3 changed files with 25 additions and 15 deletions
|
@ -314,12 +314,10 @@
|
||||||
:max-age cf/deletion-delay}
|
:max-age cf/deletion-delay}
|
||||||
|
|
||||||
:app.tasks.file-gc/handler
|
:app.tasks.file-gc/handler
|
||||||
{:pool (ig/ref :app.db/pool)
|
{:pool (ig/ref :app.db/pool)}
|
||||||
:max-age cf/deletion-delay}
|
|
||||||
|
|
||||||
:app.tasks.file-xlog-gc/handler
|
:app.tasks.file-xlog-gc/handler
|
||||||
{:pool (ig/ref :app.db/pool)
|
{:pool (ig/ref :app.db/pool)}
|
||||||
:max-age (dt/duration {:hours 72})}
|
|
||||||
|
|
||||||
:app.tasks.telemetry/handler
|
:app.tasks.telemetry/handler
|
||||||
{:pool (ig/ref :app.db/pool)
|
{:pool (ig/ref :app.db/pool)
|
||||||
|
|
|
@ -54,7 +54,7 @@
|
||||||
(recur (inc total)
|
(recur (inc total)
|
||||||
(rest files)))
|
(rest files)))
|
||||||
(do
|
(do
|
||||||
(l/info :hint "files processed" :processed total)
|
(l/info :hint "task finished" :total total)
|
||||||
|
|
||||||
;; Allow optional rollback passed by params
|
;; Allow optional rollback passed by params
|
||||||
(when (:rollback? params)
|
(when (:rollback? params)
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
"A maintenance task that performs a garbage collection of the file
|
"A maintenance task that performs a garbage collection of the file
|
||||||
change (transaction) log."
|
change (transaction) log."
|
||||||
(:require
|
(:require
|
||||||
|
[app.common.data :as d]
|
||||||
[app.common.logging :as l]
|
[app.common.logging :as l]
|
||||||
[app.db :as db]
|
[app.db :as db]
|
||||||
[app.util.time :as dt]
|
[app.util.time :as dt]
|
||||||
|
@ -16,20 +17,31 @@
|
||||||
|
|
||||||
(declare sql:delete-files-xlog)
|
(declare sql:delete-files-xlog)
|
||||||
|
|
||||||
(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 (dt/duration {:hours 72})}
|
||||||
|
(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]
|
||||||
|
(let [min-age (or (:min-age params) (:min-age cfg))]
|
||||||
(db/with-atomic [conn pool]
|
(db/with-atomic [conn pool]
|
||||||
(let [interval (db/interval max-age)
|
(let [interval (db/interval min-age)
|
||||||
result (db/exec-one! conn [sql:delete-files-xlog interval])
|
result (db/exec-one! conn [sql:delete-files-xlog interval])
|
||||||
result (:next.jdbc/update-count result)]
|
result (:next.jdbc/update-count result)]
|
||||||
(l/info :hint "old file changes removed" :total result)
|
(l/info :hint "task finished" :min-age (dt/format-duration min-age) :total result)
|
||||||
result))))
|
|
||||||
|
(when (:rollback? params)
|
||||||
|
(db/rollback! conn))
|
||||||
|
|
||||||
|
result)))))
|
||||||
|
|
||||||
(def ^:private
|
(def ^:private
|
||||||
sql:delete-files-xlog
|
sql:delete-files-xlog
|
||||||
|
|
Loading…
Reference in a new issue