0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-03-13 16:21:57 -05:00

Add improvements to the tmp file deletion scheduling

This commit is contained in:
Andrey Antukh 2023-11-08 13:33:19 +01:00
parent aaf2179b20
commit f370f28ca6
2 changed files with 15 additions and 14 deletions

View file

@ -313,7 +313,7 @@
;; to the filesystem and then read with buffered inputstream; if
;; not, read the contento into memory using bytearrays.
(if (> ^long size (* 1024 1024 2))
(let [path (tmp/tempfile :prefix "penpot.storage.s3.")
(let [path (tmp/tempfile :prefix "penpot.storage.s3." :min-age "6h")
rxf (AsyncResponseTransformer/toFile ^Path path)]
(->> (.getObject ^S3AsyncClient client
^GetObjectRequest gor

View file

@ -42,14 +42,15 @@
(defn- io-loop
[{:keys [::min-age] :as cfg}]
(l/info :hint "started tmp file cleaner")
(l/inf :hint "started tmp cleaner" :default-min-age (dt/format-duration min-age))
(try
(loop []
(when-let [path (sp/take! queue)]
(l/debug :hint "schedule tempfile deletion" :path path
(when-let [[path min-age'] (sp/take! queue)]
(let [min-age (or min-age' min-age)]
(l/dbg :hint "schedule tempfile deletion" :path path
:expires-at (dt/plus (dt/now) min-age))
(px/schedule! (inst-ms min-age) (partial remove-temp-file cfg path))
(recur)))
(px/schedule! (inst-ms min-age) (partial remove-temp-file cfg path))
(recur))))
(catch InterruptedException _
(l/trace :hint "cleaner interrupted"))
(finally
@ -57,11 +58,11 @@
(defn- remove-temp-file
"Permanently delete tempfile"
[{:keys [::wrk/executor path]}]
[{:keys [::wrk/executor]} path]
(when (fs/exists? path)
(px/run! executor
(fn []
(l/debug :hint "permanently delete tempfile" :path path)
(l/dbg :hint "permanently delete tempfile" :path path)
(fs/delete path)))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@ -70,17 +71,17 @@
(defn tempfile
"Returns a tmpfile candidate (without creating it)"
[& {:keys [suffix prefix]
[& {:keys [suffix prefix min-age]
:or {prefix "penpot."
suffix ".tmp"}}]
(let [candidate (fs/tempfile :suffix suffix :prefix prefix)]
(sp/offer! queue candidate)
candidate))
(let [path (fs/tempfile :suffix suffix :prefix prefix)]
(sp/offer! queue [path (some-> min-age dt/duration)])
path))
(defn create-tempfile
[& {:keys [suffix prefix]
[& {:keys [suffix prefix min-age]
:or {prefix "penpot."
suffix ".tmp"}}]
(let [path (fs/create-tempfile :suffix suffix :prefix prefix)]
(sp/offer! queue path)
(sp/offer! queue [path (some-> min-age dt/duration)])
path))