From ac8ef1d622854f4facef96bbf1884ed57122b414 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Thu, 11 Aug 2022 17:05:10 +0200 Subject: [PATCH] :fire: Remove completly unused file-offload task --- backend/src/app/main.clj | 11 ----- backend/src/app/tasks/file_offload.clj | 63 -------------------------- 2 files changed, 74 deletions(-) delete mode 100644 backend/src/app/tasks/file_offload.clj diff --git a/backend/src/app/main.clj b/backend/src/app/main.clj index 5628dc0cf..da0ce98bd 100644 --- a/backend/src/app/main.clj +++ b/backend/src/app/main.clj @@ -270,10 +270,6 @@ {:cron #app/cron "0 30 */3,23 * * ?" :task :telemetry} - (when (cf/get :fdata-storage-backed) - {:cron #app/cron "0 0 * * * ?" ;; hourly - :task :file-offload}) - (when (contains? cf/flags :audit-log-archive) {:cron #app/cron "0 */5 * * * ?" ;; every 5m :task :audit-log-archive}) @@ -294,7 +290,6 @@ :tasks-gc (ig/ref :app.tasks.tasks-gc/handler) :telemetry (ig/ref :app.tasks.telemetry/handler) :session-gc (ig/ref :app.http.session/gc-task) - :file-offload (ig/ref :app.tasks.file-offload/handler) :audit-log-archive (ig/ref :app.loggers.audit/archive-task) :audit-log-gc (ig/ref :app.loggers.audit/gc-task)}} @@ -326,12 +321,6 @@ {:pool (ig/ref :app.db/pool) :max-age (dt/duration {:hours 72})} - :app.tasks.file-offload/handler - {:pool (ig/ref :app.db/pool) - :max-age (dt/duration {:seconds 5}) - :storage (ig/ref :app.storage/storage) - :backend (cf/get :fdata-storage-backed :fdata-s3)} - :app.tasks.telemetry/handler {:pool (ig/ref :app.db/pool) :version (:full cf/version) diff --git a/backend/src/app/tasks/file_offload.clj b/backend/src/app/tasks/file_offload.clj deleted file mode 100644 index e429d3872..000000000 --- a/backend/src/app/tasks/file_offload.clj +++ /dev/null @@ -1,63 +0,0 @@ -;; This Source Code Form is subject to the terms of the Mozilla Public -;; License, v. 2.0. If a copy of the MPL was not distributed with this -;; file, You can obtain one at http://mozilla.org/MPL/2.0/. -;; -;; Copyright (c) UXBOX Labs SL - -(ns app.tasks.file-offload - "A maintenance task that offloads file data to an external storage (S3)." - (:require - [app.common.logging :as l] - [app.common.spec :as us] - [app.db :as db] - [app.storage :as sto] - [app.storage.impl :as simpl] - [app.util.time :as dt] - [clojure.spec.alpha :as s] - [integrant.core :as ig])) - -(def sql:offload-candidates-chunk - "select f.id, f.data from file as f - where f.data is not null - and f.modified_at < now() - ?::interval - order by f.modified_at - limit 10") - -(defn- retrieve-candidates - [{:keys [conn max-age]}] - (db/exec! conn [sql:offload-candidates-chunk max-age])) - -(defn- offload-candidate - [{:keys [storage conn backend] :as cfg} {:keys [id data] :as file}] - (l/debug :hint "offload file data" :id id) - (let [backend (simpl/resolve-backend storage backend)] - (->> (simpl/content data) - (simpl/put-object backend file)) - (db/update! conn :file - {:data nil - :data-backend (name (:id backend))} - {:id id}))) - -;; ---- STATE INIT - -(s/def ::max-age ::dt/duration) -(s/def ::backend ::us/keyword) - -(defmethod ig/pre-init-spec ::handler [_] - (s/keys :req-un [::db/pool ::max-age ::sto/storage ::backend])) - -(defmethod ig/init-key ::handler - [_ {:keys [pool max-age] :as cfg}] - (fn [_] - (db/with-atomic [conn pool] - (let [max-age (db/interval max-age) - cfg (-> cfg - (assoc :conn conn) - (assoc :max-age max-age))] - (loop [n 0] - (let [candidates (retrieve-candidates cfg)] - (if (seq candidates) - (do - (run! (partial offload-candidate cfg) candidates) - (recur (+ n (count candidates)))) - (l/debug :hint "offload summary" :count n))))))))