Skip to content

Commit

Permalink
Revert "Merge pull request #65 from ianmcorvidae/core-1183"
Browse files Browse the repository at this point in the history
This reverts commit 1ce8580, reversing
changes made to b6eec1d.
  • Loading branch information
ianmcorvidae committed Apr 12, 2024
1 parent 3865d04 commit d771a0b
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 78 deletions.
34 changes: 13 additions & 21 deletions src/data_info/clients/async_tasks.clj
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@
async-task-id))

(defn paths-async-thread
([async-task-id irods-fn end-fn]
(paths-async-thread async-task-id irods-fn end-fn true :jargon))
([async-task-id irods-fn end-fn use-client-user? conn-type]
([async-task-id jargon-fn end-fn]
(paths-async-thread async-task-id jargon-fn end-fn true))
([async-task-id jargon-fn end-fn use-client-user?]
(otel/with-span [s ["paths-async-thread" {:attributes {"async-task-id" (str async-task-id)}}]]
(let [pool (make-threadpool (str async-task-id "-async-tasks-update") 1)
{:keys [username] :as async-task} (get-by-id async-task-id)
Expand All @@ -95,24 +95,16 @@
(fn [e t] (log/error (:throwable t) "failed updating async task with started status"))
add-status async-task-id {:status "started"}))
(if use-client-user?
(if (= conn-type :jargon)
(irods/with-jargon-exceptions :client-user username [cm]
(otel/with-span [s ["irods-fn" {:attributes {"client-user" username}}]]
(irods-fn cm async-task update-fn)))
(irods/with-irods-exceptions {:jargon-opts {:client-user username}} irods
(otel/with-span [s ["irods-fn" {:attributes {"client-user" username}}]]
(irods-fn irods async-task update-fn))))
(if (= conn-type :jargon)
(irods/with-jargon-exceptions [cm]
(otel/with-span [s ["irods-fn"]]
(irods-fn cm async-task update-fn)))
(irods/with-irods-exceptions {} irods
(otel/with-span [s ["irods-fn"]]
(irods-fn irods async-task update-fn)))))
;; For the completed statuses we want a lot of retries because the presence or absence of an end date controls locking behavior
(deref (retry-via-threadpool pool 100
(fn [e t] (log/error (:throwable t) "failed updating async task with completed status"))
add-completed-status async-task-id {:status "completed" :detail (str "[" (config/service-identifier) "]")}))
(irods/with-jargon-exceptions :client-user username [cm]
(otel/with-span [s ["jargon-fn" {:attributes {"client-user" username}}]]
(jargon-fn cm async-task update-fn)))
(irods/with-jargon-exceptions [cm]
(otel/with-span [s ["jargon-fn"]]
(jargon-fn cm async-task update-fn))))
;; For the completed statuses we want a lot of retries because the presence or absence of an end date controls locking behavior
(deref (retry-via-threadpool pool 100
(fn [e t] (log/error (:throwable t) "failed updating async task with completed status"))
add-completed-status async-task-id {:status "completed" :detail (str "[" (config/service-identifier) "]")}))
(otel/with-span [s ["end-fn"]]
(end-fn async-task false))
(catch Object _
Expand Down
7 changes: 0 additions & 7 deletions src/data_info/clients/notifications.clj
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,6 @@
:message (str (completed-text failed?) " restoring " (string/join ", " start-paths) " to " (string/join ", " end-paths))}
user "restore" end-paths))

(defn path-list-notification
[user input-paths created-path failed?]
(amend-notification
{:subject (str (completed-text failed?) " creating path list " created-path " from " (count input-paths) " file(s)/folder(s)")
:message (str (completed-text failed?) " creating path list " created-path " from: " (string/join ", " input-paths))}
user "path-list" created-path))

(defn empty-trash-notification
[user failed?]
{:type "data"
Expand Down
3 changes: 1 addition & 2 deletions src/data_info/routes/path_lists.clj
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
:middleware [otel-middleware]
:query [params PathListSaveQueryParams]
:body [body (describe Paths "The folder or file paths to process for the HT Path List file contents.")]
:responses {200 {:schema {:file (describe FilteredStatInfo "File info")
:async-task-id (describe NonBlankString "An asynchronous task ID for the path list creation being handled in the background")}
:responses {200 {:schema FileStat
:description "File info for the saved HT Path List file."}}
:summary "Create an HT Path List File"
:description
Expand Down
1 change: 0 additions & 1 deletion src/data_info/routes/schemas/stats.clj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
[schema.core :as s]))

(def FileStat stats-schema/FileStat)
(def FilteredStatInfo stats-schema/FilteredStatInfo)

(s/defschema StatQueryParams
(merge StandardUserQueryParams
Expand Down
61 changes: 16 additions & 45 deletions src/data_info/services/path_lists.clj
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@
[clj-irods.validate :refer [validate]]
[clj-jargon.permissions :as perms]
[otel.otel :as otel]
[data-info.clients.async-tasks :as async-tasks]
[data-info.clients.notifications :as notifications]
[data-info.services.filetypes :as filetypes]
[data-info.services.rename :as rename]
[data-info.services.stat :as stat]
[data-info.services.stat.common :refer [process-filters]]
[data-info.services.stat.jargon :as jargon-stat]
Expand Down Expand Up @@ -138,56 +135,30 @@
(doseq [path paths]
(validators/not-base-path user path))))

(defn create-path-list*
(defn create-path-list
"Creates an HT Path List file from the given set of paths and filtering params.
The resulting HT Path List file will contain only file or only folder paths (depending on the `folders-only` param),
but no paths of folders in the initial given list will be included.
If `recursive` is true, then all subfolders (plus all their files and subfolders)
of any given folder paths are parsed and filtered as well.
Throws an error if the filtering params result in no matching paths."
[irods {:keys [user dest path-list-info-type name-pattern info-type folders-only recursive]
:or {path-list-info-type (cfg/ht-path-list-info-type)}}
{:keys [paths]}]
(otel/with-span [s ["create-path-list"]]
(validate-request-paths irods user dest paths)

(let [path-list-contents (paths->path-list irods
user
(info-type->file-identifier path-list-info-type)
name-pattern
info-type
folders-only
recursive
paths)
path-list-file-stat (with-in-str path-list-contents (copy-stream @(:jargon irods) *in* user dest))]
(irods/with-jargon-exceptions [admin-cm]
(filetypes/add-type-to-validated-path admin-cm dest path-list-info-type))
(rods/invalidate irods dest)
{:file (stat/decorate-stat irods user (cfg/irods-zone) path-list-file-stat (process-filters nil nil))})))

(defn- create-path-list-thread
[async-task-id]
(let [irods-fn (fn [irods async-task update-fn]
(let [{:keys [username data]} async-task]
(create-path-list* irods data (select-keys data [:paths]))))
end-fn (fn [async-task failed?]
(notifications/send-notification
(notifications/path-list-notification
(:username async-task)
(:paths (:data async-task))
(:dest (:data async-task))
failed?)))]
(async-tasks/paths-async-thread async-task-id irods-fn end-fn true :irods)))

(defn create-path-list
[{:keys [user dest path-list-info-type name-pattern info-type folders-only recursive]
:or {path-list-info-type (cfg/ht-path-list-info-type)}}
{:keys [paths]}]
(otel/with-span [s ["create-path-list"]]
(irods/with-irods-exceptions {:jargon-opts {:client-user user}} irods
(validate-request-paths irods user dest paths))
(let [async-task-id (async-tasks/run-async-thread
(rename/new-task "create-path-list" user {:dest dest :path-list-info-type path-list-info-type :name-pattern name-pattern :info-type info-type :folders-only folders-only :recursive recursive :paths paths})
create-path-list-thread "create-path-list")]
{:file {:path dest}
:async-task-id async-task-id})))
(validate-request-paths irods user dest paths)

(let [path-list-contents (paths->path-list irods
user
(info-type->file-identifier path-list-info-type)
name-pattern
info-type
folders-only
recursive
paths)
path-list-file-stat (with-in-str path-list-contents (copy-stream @(:jargon irods) *in* user dest))]
(irods/with-jargon-exceptions [admin-cm]
(filetypes/add-type-to-validated-path admin-cm dest path-list-info-type))
(rods/invalidate irods dest)
{:file (stat/decorate-stat irods user (cfg/irods-zone) path-list-file-stat (process-filters nil nil))}))))
4 changes: 2 additions & 2 deletions src/data_info/services/trash.clj
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
(when (seq trashed-paths)
(notifications/send-notification
(notifications/trash-notification (:username async-task) trashed-paths trash-paths failed?)))))]
(async-tasks/paths-async-thread async-task-id jargon-fn end-fn false :jargon))) ;; we don't use a client user so we can delete tickets
(async-tasks/paths-async-thread async-task-id jargon-fn end-fn false))) ;; we don't use a client user so we can delete tickets

(defn- delete-paths
([user paths]
Expand Down Expand Up @@ -160,7 +160,7 @@
(amqp/publish-msg (str "index.usage.data.user." (:username async-task)) "Update requested by data-info")
(notifications/send-notification
(notifications/empty-trash-notification (:username async-task) failed?)))]
(async-tasks/paths-async-thread async-task-id jargon-fn end-fn false :jargon))) ;; no client user, for backwards compatibility
(async-tasks/paths-async-thread async-task-id jargon-fn end-fn false))) ;; no client user, for backwards compatibility

(defn- delete-trash
"Permanently delete the contents of a user's trash directory."
Expand Down

0 comments on commit d771a0b

Please sign in to comment.