vx-consumer 0.1.5 → 0.1.6

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 610088408ab12fdbc3f8254828174a7b99beb24d
4
- data.tar.gz: 50aecdec6d9e6dcf43d7ce495615d31c02b0e9dd
3
+ metadata.gz: 47b8bcadacba1121ca2956db329217f76ce4e9b6
4
+ data.tar.gz: 679bba4a1158a235190ac403ef9919d6e198cf44
5
5
  SHA512:
6
- metadata.gz: 22051318d00559a878bf3c4b28d9fb9427f2c06f9687b0882ac1bfa6fc978b60bed45e9c23538f85da7b8ac53d1593810aaac6b6c8ddb807ff9f7db1ef4522dd
7
- data.tar.gz: 423cad5f9a2f17061e64f6c3faeb4431bc5c37cf76951d163c51659bab33592b2edbdfee94fb20e9dfeabe86b335b0910ba846ad14d5747bdc3282e958278616
6
+ metadata.gz: 2bed198aba1934ca5a6d459a63c438e94193412b145e18b9dbce5217ceebaeeb179d70fc1b2fc2ba6ea8b7ca0dba2e3f846f1cefd57965cf68079177477326eb
7
+ data.tar.gz: a7d709c2fd93a2b10a5e081b9297580a81e76571a5b61f62496a20af82c1f973505c9486e5a4481b73cec318d19d0845b7ad4d43cd1527746cb0081547709631
@@ -19,6 +19,20 @@ module Vx
19
19
  in_progress { cancel }
20
20
  end
21
21
 
22
+ def try_graceful_shutdown
23
+ if @lock.try_lock
24
+ begin
25
+ instrument('graceful_shutdown_consumer', consumer: vx_consumer_name)
26
+ cancel
27
+ ensure
28
+ @lock.unlock
29
+ end
30
+ true
31
+ else
32
+ false
33
+ end
34
+ end
35
+
22
36
  def in_progress
23
37
  @lock.synchronize do
24
38
  yield
@@ -1,5 +1,5 @@
1
1
  module Vx
2
2
  module Consumer
3
- VERSION = "0.1.5"
3
+ VERSION = "0.1.6"
4
4
  end
5
5
  end
@@ -110,7 +110,7 @@ describe Vx::Consumer do
110
110
  expect(Bob._collected.map(&:values).flatten.sort).to eq [1,2]
111
111
  end
112
112
 
113
- it "should work with graceful shutdown" do
113
+ it "should work with graceful_shutdown" do
114
114
  Bob.timeout = 1
115
115
 
116
116
  consumer = Bob.subscribe
@@ -126,6 +126,26 @@ describe Vx::Consumer do
126
126
  expect(Bob._collected).to_not be_empty
127
127
  end
128
128
 
129
+ it "should work with try_graceful_shutdown" do
130
+ Bob.timeout = 1
131
+
132
+ consumer = Bob.subscribe
133
+ 1.times do |n|
134
+ Bob.publish a: n
135
+ end
136
+
137
+ sleep 0.1
138
+ expect(consumer.try_graceful_shutdown).to be_false
139
+
140
+ Timeout.timeout(2) do
141
+ while consumer.running?
142
+ sleep 0.1
143
+ end
144
+ end
145
+
146
+ expect(consumer.try_graceful_shutdown).to be_true
147
+ end
148
+
129
149
  it "running? should be true when consumer process task" do
130
150
  Bob.timeout = 1
131
151
  consumer = Bob.subscribe
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vx-consumer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dmitry Galinsky
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-18 00:00:00.000000000 Z
11
+ date: 2014-06-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bunny