Liking cljdoc? Tell your friends :D

tservice-core.tasks.async

Provides a very simply event bus using core.async to allow publishing and subscribing to interesting topics happening throughout the tservice system in a decoupled way. It's based on metabase.events.

Regarding Events Initialization:

Internal Events: The most appropriate way to initialize event listeners in any tservice.events.* namespace (you can use setup-custom-namespace to change it) is to implement the events-init function which accepts zero arguments. This function is dynamically resolved and called exactly once when the application goes through normal startup procedures. Inside this function you can do any work needed and add your events subscribers to the bus as usual via start-event-listener!.

Examples:

; Call these code in app entrypoint.
;; First Step
(setup-custom-namespace "tservice" :sub-ns "events")

;; Second Step (Call it when the app instance is launched.)
(initialize-events!)

; Defined in each event.
;; Define event handler
(defn- test-handler! 
   [{:keys [test-content]}]
   (println test-content))

;; Define events-init function.
(def events-init
  "Automatically called during startup; start event listener for test event."
  (make-events-init "test" test-handler!))

; When you need to trigger an event, call this code 
(publish-event! "test" {:test-content "This is a test."})

External Events: If you use the event bus in plugin, you need to use make-events-init to generate event initializer and initialize the event in plugin configuration file. When the above setting is successful, you can use publish-event! to trigger an event.

Provides a very simply event bus using `core.async` to allow publishing and subscribing to interesting topics
happening throughout the tservice system in a decoupled way. It's based on `metabase.events`.

## Regarding Events Initialization:

Internal Events: The most appropriate way to initialize event listeners in any `tservice.events.*` namespace 
(you can use [[setup-custom-namespace]] to change it) is to implement the
`events-init` function which accepts zero arguments. This function is dynamically resolved and called exactly once
when the application goes through normal startup procedures. Inside this function you can do any work needed and add
your events subscribers to the bus as usual via `start-event-listener!`.

Examples:

```clojure
; Call these code in app entrypoint.
;; First Step
(setup-custom-namespace "tservice" :sub-ns "events")

;; Second Step (Call it when the app instance is launched.)
(initialize-events!)

; Defined in each event.
;; Define event handler
(defn- test-handler! 
   [{:keys [test-content]}]
   (println test-content))

;; Define events-init function.
(def events-init
  "Automatically called during startup; start event listener for test event."
  (make-events-init "test" test-handler!))

; When you need to trigger an event, call this code 
(publish-event! "test" {:test-content "This is a test."})
```

External Events: If you use the event bus in plugin, you need to use [[make-events-init]] to 
generate event initializer and initialize the event in plugin configuration file.
When the above setting is successful, you can use publish-event! to trigger an event.
raw docstring

initialize-events!clj

(initialize-events!)

Initialize the asynchronous internal events system. You need to call it when the app is launched.

Initialize the asynchronous internal events system.
You need to call it when the app is launched.
sourceraw docstring

make-events-initclj

(make-events-init event-name event-handler)

Generate event initializer.

Generate event initializer.
sourceraw docstring

object->model-idclj

(object->model-id topic object)

Determine the appropriate model_id (if possible) for a given OBJECT.

Determine the appropriate `model_id` (if possible) for a given OBJECT.
sourceraw docstring

object->user-idclj

(object->user-id object)

Determine the appropriate user_id (if possible) for a given OBJECT.

Determine the appropriate `user_id` (if possible) for a given OBJECT.
sourceraw docstring

publish-event!clj

(publish-event! topic event-item)

Publish an item into the events stream. Returns the published item to allow for chaining.

Publish an item into the events stream. Returns the published item to allow for chaining.
sourceraw docstring

setup-custom-namespaceclj

(setup-custom-namespace namespace & {:keys [sub-ns] :or {sub-ns "events"}})
source

start-event-listener!clj

(start-event-listener! topics channel handler-fn)

Initialize an event listener which runs on a background thread via go-loop.

Initialize an event listener which runs on a background thread via `go-loop`.
sourceraw docstring

stop-events!clj

(stop-events!)

Stop our events system.

Stop our events system.
sourceraw docstring

topic->modelclj

(topic->model topic)

Determine a valid model identifier for the given TOPIC.

Determine a valid `model` identifier for the given TOPIC.
sourceraw docstring

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close