From e27c0b20866394ab7086d47b65299ead0b117c7e Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Tue, 16 Apr 2024 13:51:37 +0200 Subject: [PATCH] :sparkles: Add a task for asynchronous object update operation --- backend/src/app/main.clj | 7 +++++- backend/src/app/tasks/object_update.clj | 32 +++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 backend/src/app/tasks/object_update.clj diff --git a/backend/src/app/main.clj b/backend/src/app/main.clj index 6d5fc3d5f5..97171825c1 100644 --- a/backend/src/app/main.clj +++ b/backend/src/app/main.clj @@ -349,6 +349,8 @@ :audit-log-archive (ig/ref :app.loggers.audit.archive-task/handler) :audit-log-gc (ig/ref :app.loggers.audit.gc-task/handler) + :object-update + (ig/ref :app.tasks.object-update/handler) :process-webhook-event (ig/ref ::webhooks/process-event-handler) :run-webhook @@ -376,7 +378,10 @@ ::sto/storage (ig/ref ::sto/storage)} :app.tasks.orphan-teams-gc/handler - {::db/pool (ig/ref ::db/pool)} + {::db/pool (ig/ref ::db/pool)} + + :app.tasks.object-update/handler + {::db/pool (ig/ref ::db/pool)} :app.tasks.file-gc/handler {::db/pool (ig/ref ::db/pool) diff --git a/backend/src/app/tasks/object_update.clj b/backend/src/app/tasks/object_update.clj new file mode 100644 index 0000000000..cfe5fda445 --- /dev/null +++ b/backend/src/app/tasks/object_update.clj @@ -0,0 +1,32 @@ +;; 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) KALEIDOS INC + +(ns app.tasks.object-update + "A task used for perform simple object properties update + in an asynchronous flow." + (:require + [app.common.data :as d] + [app.common.logging :as l] + [app.db :as db] + [clojure.spec.alpha :as s] + [integrant.core :as ig])) + +(defn- update-object + [{:keys [::db/conn] :as cfg} {:keys [id object key val] :as props}] + (l/trc :hint "update object prop" + :id (str id) + :object (d/name object) + :key (d/name key) + :val val) + (db/update! conn object {key val} {:id id} {::db/return-keys false})) + +(defmethod ig/pre-init-spec ::handler [_] + (s/keys :req [::db/pool])) + +(defmethod ig/init-key ::handler + [_ cfg] + (fn [{:keys [props] :as params}] + (db/tx-run! cfg update-object props)))