Skip to content

Commit 8d5b8e2

Browse files
committed
Use SQS long-polling
The intent was to use long-polling, but it wasn't implemented. This change means we will wait up to 20s on each SQS receive call in production, instead of it returning immediately. This will have two benefits: - We will make fewer SQS receive calls in production, reducing costs - We won't be spinning on receive calls in dev, reducing CPU usage from the repl process and the elasticmq docker instance
1 parent efde442 commit 8d5b8e2

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

resources/config.edn

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,17 @@
1717
:default "clojars"}}
1818
:deletion-backup-dir #profile {:production "/home/clojars/repo-deleted"
1919
:default "data/test/repo-backup"}
20-
:event-queue #profile {:production {:queue-url "https://sqs.us-east-2.amazonaws.com/825662292780/clojars-events"}
20+
:event-queue #profile {:production {:queue-url "https://sqs.us-east-2.amazonaws.com/825662292780/clojars-events"
21+
:message-wait-timeout 20}
2122
:default {:credentials {:access-key-id "fake-access-key"
2223
:secret-access-key "fake-secret-key"}
2324
:endpoint {:protocol "http"
2425
:hostname "localhost"
2526
:port 9324}
2627
:region "us-east-1"
27-
:queue-url "http://localhost:9324/000000000000/clojars-events"}}
28+
:queue-url "http://localhost:9324/000000000000/clojars-events"
29+
:message-wait-timeout #profile {:default 5
30+
:test nil}}}
2831
:github-oauth {:client-id #profile {:production #ssm-parameter "/clojars/production/github_oauth_client_id"
2932
:default "testing"}
3033
:client-secret #profile {:production #ssm-parameter "/clojars/production/github_oauth_client_secret"

src/clojars/event.clj

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,15 @@
3737
(defonce ^:private handlers (atom {}))
3838

3939
(defn- sqs-receive-loop
40-
[running? error-reporter sqs-client queue-url]
40+
[running? error-reporter sqs-client queue-url message-wait-timeout-seconds]
4141
(while @running?
4242
(try
43-
;; This will sleep up to 20s waiting on a message
43+
;; This will sleep up to message-wait-timeout-seconds waiting on a message
44+
;; if it is provided
4445
(let [res (aws-util/invoke sqs-client :ReceiveMessage
45-
{:QueueUrl queue-url})]
46+
(cond-> {:QueueUrl queue-url}
47+
message-wait-timeout-seconds
48+
(assoc :WaitTimeSeconds message-wait-timeout-seconds)))]
4649
(doseq [{:keys [Body ReceiptHandle]} (:Messages res)
4750
:let [event (edn/read-string Body)]]
4851
(doseq [handler (vals @handlers)]
@@ -72,7 +75,9 @@
7275
:running? running?
7376
:thread (future
7477
(sqs-receive-loop running? error-reporter
75-
(sqs-client config) (:queue-url config))))))
78+
(sqs-client config)
79+
(:queue-url config)
80+
(:message-wait-timeout config))))))
7681
(stop [this]
7782
(reset! (:running? this) false)
7883
(deref (:thread this) 60000 ::timeout)

0 commit comments

Comments
 (0)