mirror of
https://github.com/penpot/penpot.git
synced 2025-05-14 19:46:38 +02:00
✨ Add improvements to the tmp file deletion scheduling
This commit is contained in:
parent
aaf2179b20
commit
f370f28ca6
2 changed files with 15 additions and 14 deletions
|
@ -313,7 +313,7 @@
|
||||||
;; to the filesystem and then read with buffered inputstream; if
|
;; to the filesystem and then read with buffered inputstream; if
|
||||||
;; not, read the contento into memory using bytearrays.
|
;; not, read the contento into memory using bytearrays.
|
||||||
(if (> ^long size (* 1024 1024 2))
|
(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)]
|
rxf (AsyncResponseTransformer/toFile ^Path path)]
|
||||||
(->> (.getObject ^S3AsyncClient client
|
(->> (.getObject ^S3AsyncClient client
|
||||||
^GetObjectRequest gor
|
^GetObjectRequest gor
|
||||||
|
|
|
@ -42,14 +42,15 @@
|
||||||
|
|
||||||
(defn- io-loop
|
(defn- io-loop
|
||||||
[{:keys [::min-age] :as cfg}]
|
[{: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
|
(try
|
||||||
(loop []
|
(loop []
|
||||||
(when-let [path (sp/take! queue)]
|
(when-let [[path min-age'] (sp/take! queue)]
|
||||||
(l/debug :hint "schedule tempfile deletion" :path path
|
(let [min-age (or min-age' min-age)]
|
||||||
|
(l/dbg :hint "schedule tempfile deletion" :path path
|
||||||
:expires-at (dt/plus (dt/now) min-age))
|
:expires-at (dt/plus (dt/now) min-age))
|
||||||
(px/schedule! (inst-ms min-age) (partial remove-temp-file cfg path))
|
(px/schedule! (inst-ms min-age) (partial remove-temp-file cfg path))
|
||||||
(recur)))
|
(recur))))
|
||||||
(catch InterruptedException _
|
(catch InterruptedException _
|
||||||
(l/trace :hint "cleaner interrupted"))
|
(l/trace :hint "cleaner interrupted"))
|
||||||
(finally
|
(finally
|
||||||
|
@ -57,11 +58,11 @@
|
||||||
|
|
||||||
(defn- remove-temp-file
|
(defn- remove-temp-file
|
||||||
"Permanently delete tempfile"
|
"Permanently delete tempfile"
|
||||||
[{:keys [::wrk/executor path]}]
|
[{:keys [::wrk/executor]} path]
|
||||||
(when (fs/exists? path)
|
(when (fs/exists? path)
|
||||||
(px/run! executor
|
(px/run! executor
|
||||||
(fn []
|
(fn []
|
||||||
(l/debug :hint "permanently delete tempfile" :path path)
|
(l/dbg :hint "permanently delete tempfile" :path path)
|
||||||
(fs/delete path)))))
|
(fs/delete path)))))
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
@ -70,17 +71,17 @@
|
||||||
|
|
||||||
(defn tempfile
|
(defn tempfile
|
||||||
"Returns a tmpfile candidate (without creating it)"
|
"Returns a tmpfile candidate (without creating it)"
|
||||||
[& {:keys [suffix prefix]
|
[& {:keys [suffix prefix min-age]
|
||||||
:or {prefix "penpot."
|
:or {prefix "penpot."
|
||||||
suffix ".tmp"}}]
|
suffix ".tmp"}}]
|
||||||
(let [candidate (fs/tempfile :suffix suffix :prefix prefix)]
|
(let [path (fs/tempfile :suffix suffix :prefix prefix)]
|
||||||
(sp/offer! queue candidate)
|
(sp/offer! queue [path (some-> min-age dt/duration)])
|
||||||
candidate))
|
path))
|
||||||
|
|
||||||
(defn create-tempfile
|
(defn create-tempfile
|
||||||
[& {:keys [suffix prefix]
|
[& {:keys [suffix prefix min-age]
|
||||||
:or {prefix "penpot."
|
:or {prefix "penpot."
|
||||||
suffix ".tmp"}}]
|
suffix ".tmp"}}]
|
||||||
(let [path (fs/create-tempfile :suffix suffix :prefix prefix)]
|
(let [path (fs/create-tempfile :suffix suffix :prefix prefix)]
|
||||||
(sp/offer! queue path)
|
(sp/offer! queue [path (some-> min-age dt/duration)])
|
||||||
path))
|
path))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue