mirror of
https://github.com/penpot/penpot.git
synced 2025-05-25 18:56:13 +02:00
✨ Add better error reporting on offload-file-data task
This commit is contained in:
parent
7df68bb8bd
commit
77c45ed109
1 changed files with 23 additions and 17 deletions
|
@ -8,6 +8,7 @@
|
||||||
"A maintenance task responsible of moving file data from hot
|
"A maintenance task responsible of moving file data from hot
|
||||||
storage (the database row) to a cold storage (fs or s3)."
|
storage (the database row) to a cold storage (fs or s3)."
|
||||||
(:require
|
(:require
|
||||||
|
[app.common.exceptions :as ex]
|
||||||
[app.common.logging :as l]
|
[app.common.logging :as l]
|
||||||
[app.db :as db]
|
[app.db :as db]
|
||||||
[app.db.sql :as-alias sql]
|
[app.db.sql :as-alias sql]
|
||||||
|
@ -18,26 +19,31 @@
|
||||||
(defn- offload-file-data!
|
(defn- offload-file-data!
|
||||||
[{:keys [::db/conn ::sto/storage ::file-id] :as cfg}]
|
[{:keys [::db/conn ::sto/storage ::file-id] :as cfg}]
|
||||||
(let [file (db/get conn :file {:id file-id}
|
(let [file (db/get conn :file {:id file-id}
|
||||||
{::sql/for-update true})
|
{::sql/for-update true})]
|
||||||
|
(when (nil? (:data file))
|
||||||
|
(ex/raise :hint "file already offloaded"
|
||||||
|
:type :internal
|
||||||
|
:code :file-already-offloaded
|
||||||
|
:file-id file-id))
|
||||||
|
|
||||||
data (sto/content (:data file))
|
(let [data (sto/content (:data file))
|
||||||
sobj (sto/put-object! storage
|
sobj (sto/put-object! storage
|
||||||
{::sto/content data
|
{::sto/content data
|
||||||
::sto/touch true
|
::sto/touch true
|
||||||
:bucket "file-data"
|
:bucket "file-data"
|
||||||
:content-type "application/octet-stream"
|
:content-type "application/octet-stream"
|
||||||
:file-id file-id})]
|
:file-id file-id})]
|
||||||
|
|
||||||
(l/trc :hint "offload file data"
|
(l/trc :hint "offload file data"
|
||||||
:file-id (str file-id)
|
:file-id (str file-id)
|
||||||
:storage-id (str (:id sobj)))
|
:storage-id (str (:id sobj)))
|
||||||
|
|
||||||
(db/update! conn :file
|
(db/update! conn :file
|
||||||
{:data-backend "objects-storage"
|
{:data-backend "objects-storage"
|
||||||
:data-ref-id (:id sobj)
|
:data-ref-id (:id sobj)
|
||||||
:data nil}
|
:data nil}
|
||||||
{:id file-id}
|
{:id file-id}
|
||||||
{::db/return-keys false})))
|
{::db/return-keys false}))))
|
||||||
|
|
||||||
(defn- offload-file-data-fragments!
|
(defn- offload-file-data-fragments!
|
||||||
[{:keys [::db/conn ::sto/storage ::file-id] :as cfg}]
|
[{:keys [::db/conn ::sto/storage ::file-id] :as cfg}]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue