Skip to content

Commit 5e81a73

Browse files
authored
Merge pull request #13 from toyokumo/bugfix/not-to-take-extra-signs
Do not take extra signs from consume-chan
2 parents 8c71148 + eae4bb0 commit 5e81a73

File tree

3 files changed

+26
-18
lines changed

3 files changed

+26
-18
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Change Log
22

33
## [Unreleased]
4+
### Fixed
5+
* Fixed `respond` and `raise` not to take extra signs when these functions are called more than once.
46

57
## 0.4.87
68
### Changed

src/gluttony/record/consumer.clj

+22-18
Original file line numberDiff line numberDiff line change
@@ -51,27 +51,31 @@
5151

5252
(defn- respond*
5353
[{:keys [client queue-url consume-chan]} p message]
54-
(deliver p :respond)
55-
(a/go
56-
(when consume-chan
57-
;; takes a sign and make a space in which next consume can work
58-
(a/<! consume-chan)
59-
(log/debugf "takes a sign of message-id:%s" (:message-id message)))
60-
(a/<! (sqs/delete-message client {:queue-url queue-url
61-
:receipt-handle (:receipt-handle message)}))))
54+
(let [already-realized? (realized? p)]
55+
(deliver p :respond)
56+
(a/go
57+
(when (and consume-chan
58+
(not already-realized?))
59+
;; takes a sign and make a space in which next consume can work
60+
(a/<! consume-chan)
61+
(log/debugf "takes a sign of message-id:%s" (:message-id message)))
62+
(a/<! (sqs/delete-message client {:queue-url queue-url
63+
:receipt-handle (:receipt-handle message)})))))
6264

6365
(defn- raise*
6466
[{:keys [client queue-url consume-chan]} p message & [retry-delay]]
65-
(deliver p :raise)
66-
(a/go
67-
(when consume-chan
68-
;; takes a sign and make a space in which next consume can work
69-
(a/<! consume-chan)
70-
(log/debugf "takes a sign of message-id:%s" (:message-id message)))
71-
(let [retry-delay (or retry-delay 0)]
72-
(a/<! (sqs/change-message-visibility client {:queue-url queue-url
73-
:receipt-handle (:receipt-handle message)
74-
:visibility-timeout retry-delay})))))
67+
(let [already-realized? (realized? p)]
68+
(deliver p :raise)
69+
(a/go
70+
(when (and consume-chan
71+
(not already-realized?))
72+
;; takes a sign and make a space in which next consume can work
73+
(a/<! consume-chan)
74+
(log/debugf "takes a sign of message-id:%s" (:message-id message)))
75+
(let [retry-delay (or retry-delay 0)]
76+
(a/<! (sqs/change-message-visibility client {:queue-url queue-url
77+
:receipt-handle (:receipt-handle message)
78+
:visibility-timeout retry-delay}))))))
7579

7680
(defn- heartbeat*
7781
"When heartbeat parameter is set, a heartbeat process start after the first heartbeat"

test/gluttony/core_test.clj

+2
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,8 @@
181181
(a/<! (a/timeout 10)) ; Make a point of park
182182
(swap! collected
183183
conj Integer/MIN_VALUE)
184+
(respond)
185+
;; Respond twice on purpose
184186
(respond)))
185187
consumer (start-consumer queue-url consume
186188
{:client th/client

0 commit comments

Comments
 (0)