;; When using the `sync-operation` macro below the BODY of the macro will be executed in the context of several different
;; functions below that do things like prevent duplicate operations from being ran simultaneously and taking care of
;; things like event publishing, error handling, and logging.
;; When using the `sync-operation` macro below the BODY of the macro will be executed in the context of several
;; different functions below that do things like prevent duplicate operations from being ran simultaneously and taking
;; care of things like event publishing, error handling, and logging.
;;
;; These basically operate in a middleware pattern, where the various different steps take a function, and return a new function
;; that will execute the original in whatever context or with whatever side effects appropriate for that step.
;; These basically operate in a middleware pattern, where the various different steps take a function, and return a
;; new function that will execute the original in whatever context or with whatever side effects appropriate for that
;; step.
;; This looks something like {:sync #{1 2}, :cache #{2 3}} when populated.
;; Key is a type of sync operation, e.g. `:sync` or `:cache`; vals are sets of DB IDs undergoing that operation.
;; TODO - as @salsakran mentioned it would be nice to do this via the DB so we could better support multi-instance setups in the future
;;
;; TODO - as @salsakran mentioned it would be nice to do this via the DB so we could better support multi-instance
;; setups in the future
(defonce^:privateoperation->db-ids(atom{}))
(defnwith-duplicate-ops-prevented
"Run F in a way that will prevent it from simultaneously being ran more for a single database more than once for a given OPERATION.
This prevents duplicate sync-like operations from taking place for a given DB, e.g. if a user hits the `Sync` button in the admin panel multiple times.
"Run F in a way that will prevent it from simultaneously being ran more for a single database more than once for a
given OPERATION. This prevents duplicate sync-like operations from taking place for a given DB, e.g. if a user hits
the `Sync` button in the admin panel multiple times.
;; Only one `sync-db!` for `database-id` will be allowed at any given moment; duplicates will be ignored
(with-duplicate-ops-prevented :sync database-id
#(sync-db! database-id))"
;; Only one `sync-db!` for `database-id` will be allowed at any given moment; duplicates will be ignored
(with-duplicate-ops-prevented :sync database-id
#(sync-db! database-id))"
{:style/indent2}
[operationdatabase-or-idf]
(fn[]
...
...
@@ -53,8 +58,8 @@
(defn-with-sync-events
"Publish events related to beginning and ending a sync-like process, e.g. `:sync-database` or `:cache-values`, for a DATABASE-ID.
F is executed between the logging of the two events."
"Publish events related to beginning and ending a sync-like process, e.g. `:sync-database` or `:cache-values`, for a
DATABASE-ID. F is executed between the logging of the two events."
;; we can do everyone a favor and infer the name of the individual begin and sync events