diff --git a/backend/src/app/main.clj b/backend/src/app/main.clj index 4a8119d3e..1e909f822 100644 --- a/backend/src/app/main.clj +++ b/backend/src/app/main.clj @@ -166,10 +166,9 @@ :executor (ig/ref ::wrk/executor) :redis (ig/ref ::rds/redis)} - ;; TODO: refactor execution model :app.storage.tmp/cleaner - {:executor (ig/ref ::wrk/executor) - :scheduled-executor (ig/ref ::wrk/scheduled-executor)} + {::wrk/executor (ig/ref ::wrk/executor) + ::wrk/scheduled-executor (ig/ref ::wrk/scheduled-executor)} ::sto/gc-deleted-task {:pool (ig/ref ::db/pool) diff --git a/backend/src/app/storage/tmp.clj b/backend/src/app/storage/tmp.clj index 1fd069ef3..3e64e6bfc 100644 --- a/backend/src/app/storage/tmp.clj +++ b/backend/src/app/storage/tmp.clj @@ -12,6 +12,7 @@ (:require [app.common.data :as d] [app.common.logging :as l] + [app.storage :as-alias sto] [app.util.time :as dt] [app.worker :as wrk] [clojure.core.async :as a] @@ -23,42 +24,43 @@ (declare remove-temp-file) (defonce queue (a/chan 128)) -(s/def ::min-age ::dt/duration) (defmethod ig/pre-init-spec ::cleaner [_] - (s/keys :req-un [::min-age ::wrk/scheduled-executor ::wrk/executor])) + (s/keys :req [::sto/min-age ::wrk/scheduled-executor])) (defmethod ig/prep-key ::cleaner [_ cfg] - (merge {:min-age (dt/duration {:minutes 30})} + (merge {::sto/min-age (dt/duration "30m")} (d/without-nils cfg))) (defmethod ig/init-key ::cleaner - [_ {:keys [scheduled-executor executor min-age] :as cfg}] - (l/info :hint "starting tempfile cleaner service") - (let [cch (a/chan)] - (a/go-loop [] - (let [[path port] (a/alts! [queue cch])] - (when (not= port cch) + [_ {:keys [::sto/min-age ::wrk/scheduled-executor] :as cfg}] + (px/thread + {:name "penpot/storage-tmp-cleaner"} + (try + (l/info :hint "started tmp file cleaner") + (loop [] + (when-let [path (a/ close-ch a/close!)) + [_ thread] + (px/interrupt! thread)) (defn- remove-temp-file "Permanently delete tempfile" - [executor path] - (px/with-dispatch executor - (l/trace :hint "permanently delete tempfile" :path path) - (when (fs/exists? path) - (fs/delete path)))) + [path] + (l/trace :hint "permanently delete tempfile" :path path) + (when (fs/exists? path) + (fs/delete path))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; API