Skip to content

Commit dbe8769

Browse files
committed
Convert receive loop to Thread
The future is swallowing errors, so we will use a bare Thread here. This should allow an exception in SQS processing to trigger the uncaught-exception-handler, exiting the process. Systemd will then restart it. Otherwise, SQS receiving stops, and we stop processing async tasks until the process is restarted.
1 parent 9e5c17a commit dbe8769

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/clojars/event.clj

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
[cognitect.aws.credentials :as credentials]
99
[com.stuartsierra.component :as component]))
1010

11+
(set! *warn-on-reflection* true)
12+
1113
(defn- sqs-client
1214
[{:as _config :keys [credentials endpoint region]}]
1315
(doto (aws/client (cond-> {:api :sqs}
@@ -77,14 +79,16 @@
7779
(let [running? (atom true)]
7880
(assoc this
7981
:running? running?
80-
:thread (future
81-
(sqs-receive-loop running? error-reporter
82-
(sqs-client config)
83-
(:queue-url config)
84-
(:message-wait-timeout config))))))
82+
:thread (doto (Thread.
83+
(fn []
84+
(sqs-receive-loop running? error-reporter
85+
(sqs-client config)
86+
(:queue-url config)
87+
(:message-wait-timeout config))))
88+
(.start)))))
8589
(stop [this]
8690
(reset! (:running? this) false)
87-
(deref (:thread this) 60000 ::timeout)
91+
(.join ^Thread (:thread this) 60000)
8892
this))
8993

9094
(defn new-sqs-receiver

0 commit comments

Comments
 (0)