Skip to content

Commit 240b8b2

Browse files
committed
feat: add mq component in itself
1 parent 1e2c153 commit 240b8b2

File tree

2 files changed

+25
-17
lines changed

2 files changed

+25
-17
lines changed

src/com/moclojer/components/mq.clj

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,22 +50,22 @@
5050
component/Lifecycle
5151
(start [this]
5252
(logs/log :info "starting mq")
53-
(let [components {:config config
53+
(let [client (rq/create-client (get-in config [:config :mq :uri]))
54+
base-this (assoc this :client client)
55+
components {:config config
5456
:database database
5557
:storage storage
5658
:http http
57-
:sentry sentry}
58-
client (rq/create-client (get-in config [:config :mq :uri]))
59+
:sentry sentry
60+
:mq base-this}
5961
wrapped-workers (map #(wrap-worker % components sentry) workers)
6062
subs (rq-pubsub/subscribe! client wrapped-workers :blocking? blocking?)]
6163

6264
(doseq [job jobs]
63-
(start-job! (assoc this :client client) job))
65+
(start-job! base-this job))
6466

65-
(merge this {:client client
66-
:subs subs
67-
:jobs jobs
68-
:components components})))
67+
(merge this (assoc base-this :components components)
68+
{:subs subs :jobs jobs})))
6969
(stop [this]
7070
(logs/log :info "stopping mq")
7171
(when-let [?client (:client this)]

test/com/moclojer/components/mq_test.clj

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,23 @@
4747
{:init (utils/start-system! create-and-start-system)
4848
:cleanup utils/stop-system!
4949
:fail-fast? true}
50-
#_(flow
51-
"should publish and consume a message"
52-
(publish-message {:event "test"} "test")
53-
(flow "sleeping and check the state"
54-
(match? {:event "test"}
55-
(state/return
56-
(utils/exec-with-timeout
57-
#(deref state)
58-
10000 500)))))
50+
51+
(flow
52+
"should have itself in the components"
53+
[mq (state-flow.api/get-state :mq)]
54+
(match?
55+
(get-in mq [:components :mq :client])
56+
(:client mq)))
57+
58+
(flow
59+
"should publish and consume a message"
60+
(publish-message {:event "test"} "test")
61+
(flow "sleeping and check the state"
62+
(match? {:event "test"}
63+
(state/return
64+
(utils/exec-with-timeout
65+
#(deref state)
66+
10000 500)))))
5967
(flow
6068
"should trigger a job 2 times within 5.5 seconds"
6169
[:let [job {:channel "test-job"

0 commit comments

Comments
 (0)