diff --git a/backend/src/app/main.clj b/backend/src/app/main.clj index da0ce98bd..c89c5b376 100644 --- a/backend/src/app/main.clj +++ b/backend/src/app/main.clj @@ -314,12 +314,10 @@ :max-age cf/deletion-delay} :app.tasks.file-gc/handler - {:pool (ig/ref :app.db/pool) - :max-age cf/deletion-delay} + {:pool (ig/ref :app.db/pool)} :app.tasks.file-xlog-gc/handler - {:pool (ig/ref :app.db/pool) - :max-age (dt/duration {:hours 72})} + {:pool (ig/ref :app.db/pool)} :app.tasks.telemetry/handler {:pool (ig/ref :app.db/pool) diff --git a/backend/src/app/tasks/file_gc.clj b/backend/src/app/tasks/file_gc.clj index d9fe8a498..bd7ff71d4 100644 --- a/backend/src/app/tasks/file_gc.clj +++ b/backend/src/app/tasks/file_gc.clj @@ -54,7 +54,7 @@ (recur (inc total) (rest files))) (do - (l/info :hint "files processed" :processed total) + (l/info :hint "task finished" :total total) ;; Allow optional rollback passed by params (when (:rollback? params) diff --git a/backend/src/app/tasks/file_xlog_gc.clj b/backend/src/app/tasks/file_xlog_gc.clj index 88c2b1225..6971f198a 100644 --- a/backend/src/app/tasks/file_xlog_gc.clj +++ b/backend/src/app/tasks/file_xlog_gc.clj @@ -8,6 +8,7 @@ "A maintenance task that performs a garbage collection of the file change (transaction) log." (:require + [app.common.data :as d] [app.common.logging :as l] [app.db :as db] [app.util.time :as dt] @@ -16,20 +17,31 @@ (declare sql:delete-files-xlog) -(s/def ::max-age ::dt/duration) +(s/def ::min-age ::dt/duration) (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 - [_ {:keys [pool max-age] :as cfg}] - (fn [_] - (db/with-atomic [conn pool] - (let [interval (db/interval max-age) - result (db/exec-one! conn [sql:delete-files-xlog interval]) - result (:next.jdbc/update-count result)] - (l/info :hint "old file changes removed" :total result) - result)))) + [_ {:keys [pool] :as cfg}] + (fn [params] + (let [min-age (or (:min-age params) (:min-age cfg))] + (db/with-atomic [conn pool] + (let [interval (db/interval min-age) + result (db/exec-one! conn [sql:delete-files-xlog interval]) + result (:next.jdbc/update-count result)] + (l/info :hint "task finished" :min-age (dt/format-duration min-age) :total result) + + (when (:rollback? params) + (db/rollback! conn)) + + result))))) (def ^:private sql:delete-files-xlog