Skip to content

Commit

Permalink
Convert receive loop to Thread
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tobias committed Feb 5, 2024
1 parent 9e5c17a commit dbe8769
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/clojars/event.clj
Expand Up @@ -8,6 +8,8 @@
[cognitect.aws.credentials :as credentials]
[com.stuartsierra.component :as component]))

(set! *warn-on-reflection* true)

(defn- sqs-client
[{:as _config :keys [credentials endpoint region]}]
(doto (aws/client (cond-> {:api :sqs}
Expand Down Expand Up @@ -77,14 +79,16 @@
(let [running? (atom true)]
(assoc this
:running? running?
:thread (future
(sqs-receive-loop running? error-reporter
(sqs-client config)
(:queue-url config)
(:message-wait-timeout config))))))
:thread (doto (Thread.
(fn []
(sqs-receive-loop running? error-reporter
(sqs-client config)
(:queue-url config)
(:message-wait-timeout config))))
(.start)))))
(stop [this]
(reset! (:running? this) false)
(deref (:thread this) 60000 ::timeout)
(.join ^Thread (:thread this) 60000)
this))

(defn new-sqs-receiver
Expand Down

0 comments on commit dbe8769

Please sign in to comment.