nsq-ruby 1.4.0 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +28 -1
  3. data/lib/nsq/consumer.rb +13 -0
  4. data/lib/version.rb +1 -1
  5. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b35d1cfb3f84900faa925a11816c604c2d36d6cc
4
- data.tar.gz: 0158497d7aaaa82cd5488589fb97b4361831eccd
3
+ metadata.gz: 1cc303464874107233049891324ba89f7fdabeb9
4
+ data.tar.gz: f8f0d0d615f723893babdca18401221c0f86bbf8
5
5
  SHA512:
6
- metadata.gz: 7ee7047f73fd426b3825f814cace21c87cc04997975cf20c67a9e7f1b4680dd1d2b41632ca0d40c6d9086e4accb4b4a83acf43d7277166f904118be54e9d2dba
7
- data.tar.gz: 4067ac682d665fb700b8e6918ce7c4a8656b1376dfd12bb3ecb1f1845f2731f4a0de8776b6421fded2ca65c9f567410074baacbc3670daae74c490d0d6fc2e12
6
+ metadata.gz: f797afecb530034108857cfee09ff0fb17d41d715d80cb1f10dfc527801de8ebc1cd707348908e743108a61ebddd942f1f964cadf4abb452d7a9f749572bb75d
7
+ data.tar.gz: b34ed2daeed5f863b6f81cf53d787fb4d11bbda45eaeabc01e5a75c33f9a7373ff72aadb4731ac7ca2b9df272ac15486dd97e59248acb7f8d0471937ba67ed89
data/README.md CHANGED
@@ -187,6 +187,32 @@ message = consumer.pop
187
187
  If there are messages on the queue, `pop` will return one immediately. If there
188
188
  are no messages on the queue, `pop` will block execution until one arrives.
189
189
 
190
+ Be aware, while `#pop` is blocking, your process will be unresponsive. This
191
+ can be a problem in certain cases, like if you're trying to gracefully restart
192
+ a worker process by sending it a `TERM` signal. See `#pop_without_blocking` for
193
+ information on how to mitigate this issue.
194
+
195
+
196
+ ### `#pop_without_blocking`
197
+
198
+ This is just like `#pop` except it doesn't block. It always returns immediately.
199
+ If there are no messages in the queue, it will return `nil`.
200
+
201
+ If you're consuming from a low-volume topic and don't want to get stuck in a
202
+ blocking state, you can use this method to consume messages like so:
203
+
204
+ ```Ruby
205
+ loop do
206
+ if msg = @messages.pop_without_blocking
207
+ # do something
208
+ msg.finish
209
+ else
210
+ # wait for a bit before checking for new messages
211
+ sleep 0.01
212
+ end
213
+ end
214
+ ```
215
+
190
216
 
191
217
  ### `#size`
192
218
 
@@ -301,11 +327,12 @@ millions of messages a day.
301
327
  - Robby Grossman (@freerobby)
302
328
  - Brendan Schwartz (@bschwartz)
303
329
  - Marshall Moutenot (@mmoutenot)
330
+ - Danielle Sucher (@DanielleSucher)
304
331
 
305
332
 
306
333
  ## MIT License
307
334
 
308
- Copyright (C) 2014 Wistia, Inc.
335
+ Copyright (C) 2016 Wistia, Inc.
309
336
 
310
337
  Permission is hereby granted, free of charge, to any person obtaining a copy of
311
338
  this software and associated documentation files (the "Software"), to deal in
@@ -48,6 +48,19 @@ module Nsq
48
48
  end
49
49
 
50
50
 
51
+ # By default, if the internal queue is empty, pop will block until
52
+ # a new message comes in.
53
+ #
54
+ # Calling this method won't block. If there are no messages, it just
55
+ # returns nil.
56
+ def pop_without_blocking
57
+ @messages.pop(true)
58
+ rescue ThreadError
59
+ # When the Queue is empty calling `Queue#pop(true)` will raise a ThreadError
60
+ nil
61
+ end
62
+
63
+
51
64
  # returns the number of messages we have locally in the queue
52
65
  def size
53
66
  @messages.size
@@ -1,7 +1,7 @@
1
1
  module Nsq
2
2
  module Version
3
3
  MAJOR = 1
4
- MINOR = 4
4
+ MINOR = 5
5
5
  PATCH = 0
6
6
  BUILD = nil
7
7
  STRING = [MAJOR, MINOR, PATCH, BUILD].compact.join('.')
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nsq-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wistia
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-24 00:00:00.000000000 Z
11
+ date: 2015-12-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler