watership 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/watership/consumer.rb +59 -0
- data/lib/watership/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b0b8d54b5999ef624829bbc4fe0ff41d4ba19294
|
4
|
+
data.tar.gz: b59528de0c83ceca9e8a4e58fae7df5e08724ef0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4e4976bd54777b0dbb6daa18fac5154d364756fadf0367cdd3756fdecabbc414d86b987b4a2da01274367bae0ec9f8ddae61b1d042f2a19f61898cdd5635a0b5
|
7
|
+
data.tar.gz: d546eedabcf120b3d6f94d8e28ea9935d1aaf40483b94ac75715c7a7aca1d25fba11bfad5b2fdfe2ba12810bf40b75cd395ac0499aff3c876eb437906685ef4a
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require "json"
|
2
|
+
|
3
|
+
module Watership
|
4
|
+
class Consumer
|
5
|
+
def initialize(consumer, url)
|
6
|
+
@consumer = consumer
|
7
|
+
@url = url
|
8
|
+
end
|
9
|
+
|
10
|
+
def consume
|
11
|
+
Thread.abort_on_exception = true
|
12
|
+
begin
|
13
|
+
queue.subscribe(block: true, ack: true) do |delivery_info, properties, payload|
|
14
|
+
success = false
|
15
|
+
begin
|
16
|
+
@consumer.call(JSON.parse(payload))
|
17
|
+
success = true
|
18
|
+
rescue StandardError => exception
|
19
|
+
Rails.logger.error "Error thrown in subscribe block"
|
20
|
+
Rails.logger.error exception.message
|
21
|
+
Rails.logger.error exception.backtrace.join("\n")
|
22
|
+
Airbrake.notify(exception) if defined? AirBrake
|
23
|
+
Rails.logger.info "Rejecting in rabbit"
|
24
|
+
throw(:terminate)
|
25
|
+
rescue Interrupt => exception
|
26
|
+
Rails.logger.error "Interrupt in subscribe block"
|
27
|
+
Rails.logger.warn "Stopped gracefully."
|
28
|
+
throw(:terminate)
|
29
|
+
ensure
|
30
|
+
if success
|
31
|
+
Rails.logger.info "Acking message"
|
32
|
+
channel.acknowledge(delivery_info.delivery_tag, false)
|
33
|
+
else
|
34
|
+
Rails.logger.info "Rejecting message"
|
35
|
+
channel.reject(delivery_info.delivery_tag, true)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
ensure
|
40
|
+
Rails.logger.info "Closing Channel"
|
41
|
+
channel.close
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def queue
|
48
|
+
@queue ||= channel.queue(@consumer.class::QUEUE, durable: true)
|
49
|
+
end
|
50
|
+
|
51
|
+
def connection
|
52
|
+
@connection ||= Bunny.new(@url).tap { |bunny| bunny.start }
|
53
|
+
end
|
54
|
+
|
55
|
+
def channel
|
56
|
+
@connection ||= connection.create_channel
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
data/lib/watership/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: watership
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Scofield
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-05-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -80,6 +80,7 @@ files:
|
|
80
80
|
- README.md
|
81
81
|
- Rakefile
|
82
82
|
- lib/watership.rb
|
83
|
+
- lib/watership/consumer.rb
|
83
84
|
- lib/watership/subscriber.rb
|
84
85
|
- lib/watership/version.rb
|
85
86
|
- watership.gemspec
|