watership 0.8.2 → 0.9.0pre
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -13
- data/bin/watership-consume +43 -0
- data/lib/watership/consumer.rb +9 -8
- data/lib/watership/version.rb +1 -1
- metadata +17 -15
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
YWY5OWE4ZmM2ZmYxMWFlZGYxOTQ4M2VhNWFhZmNiMmQzZmYxNzlkOQ==
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: af4e4c123875a9ec4bed6e1245ceb48024df628e
|
4
|
+
data.tar.gz: 8730ce20f09f1fe7ffdd4045af210e90622c9814
|
7
5
|
SHA512:
|
8
|
-
metadata.gz:
|
9
|
-
|
10
|
-
Njk5MTQxMzYyM2I2YmRkNDI0Zjk5ZjBkODRlNjhjODBhM2NhY2I2ZTljMzA2
|
11
|
-
YzU1NWE5Nzc5N2E0NGM5NDQzZjYzZDNkMWNkOTU2YzMzY2IwMzI=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
YzZlZDNjMTQ1NjNjOGQwZGIwNjZiZWE1MWI3ZGEyOTI3M2FmN2VlZjE2Njli
|
14
|
-
YTY0ZDk3OWMzYTlhMDM2YTMzZTRmMzczMWNlOGQ1N2U2ZTAzOTc1ZjBmZmI0
|
15
|
-
NzRkYWIxODIyNjQwMTFhNTIyY2VkY2I4NmU3Zjk0Y2FhNzJjYWE=
|
6
|
+
metadata.gz: cac3ffbf712948c61604af1bf4dd1d4941d9bc9e08fac2f59dd550a3a20f36f6aaf24accff0a749b14790468cb8c3bb30cbeea7e56314d023ee2d7d9b093d2d9
|
7
|
+
data.tar.gz: 0ed76325b78f98ac060695eefebf6720bd589f55990c738566390e2a42154a7b4fea060325f2e1322d08343aa616c7c2a7aeacc536a06a0e8562506060187984
|
@@ -0,0 +1,43 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
ENV["LIBRATO_AUTORUN"] = "1"
|
4
|
+
concurrency = Integer(ENV.fetch("WORKER_CONCURRENCY", "2"))
|
5
|
+
ENV["DB_POOL"] = (concurrency + 1).to_s
|
6
|
+
require File.expand_path('config/environment', Dir.pwd)
|
7
|
+
require "watership/consumer"
|
8
|
+
url = ENV.fetch("CONSUMER_AMQP_URI")
|
9
|
+
|
10
|
+
require 'optparse'
|
11
|
+
options = {}
|
12
|
+
OptionParser.new do |opts|
|
13
|
+
opts.banner = "Usage: watership-consume [options]"
|
14
|
+
|
15
|
+
opts.on("-c", "--class class", "Consumer class to use") do |v|
|
16
|
+
options[:class] = v
|
17
|
+
end
|
18
|
+
|
19
|
+
opts.on("-b", "--bind binding", "Bind to a queue (with routing key after /)") do |v|
|
20
|
+
if v =~ %r{/}
|
21
|
+
parts = v.split("/")
|
22
|
+
options[:bind] = parts[0]
|
23
|
+
options[:routing_key] = parts[1]
|
24
|
+
else
|
25
|
+
options[:bind] = v
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end.parse!
|
29
|
+
|
30
|
+
puts options.inspect
|
31
|
+
|
32
|
+
consumer = Watership::Consumer.new(options[:class].constantize, url, concurrency: concurrency)
|
33
|
+
|
34
|
+
if options[:bind]
|
35
|
+
args = if options[:routing_key]
|
36
|
+
[options[:bind], routing_key: options[:routing_key]]
|
37
|
+
else
|
38
|
+
[options[:bind]]
|
39
|
+
end
|
40
|
+
consumer.bind(*args)
|
41
|
+
end
|
42
|
+
|
43
|
+
consumer.consume
|
data/lib/watership/consumer.rb
CHANGED
@@ -10,18 +10,16 @@ module Watership
|
|
10
10
|
@prefetch = channel_options.delete(:prefetch) || Integer(ENV.fetch("RABBIT_CONSUMER_PREFETCH", 200))
|
11
11
|
@concurrency = channel_options.delete(:concurrency) || 1
|
12
12
|
@channel_opts = {durable: true}.merge(channel_options)
|
13
|
-
@queue_opts = {block: false,
|
13
|
+
@queue_opts = {block: false, manual_ack: true}.merge(queue_options)
|
14
14
|
end
|
15
15
|
|
16
|
-
def consume
|
17
|
-
logger.error("Don't provide an argument to Consumer#consume") unless donotuse == :donotuse
|
18
|
-
|
16
|
+
def consume
|
19
17
|
Thread.abort_on_exception = true
|
20
18
|
@concurrency.times do
|
21
19
|
queue.subscribe(@queue_opts) do |delivery_info, properties, payload|
|
22
20
|
begin
|
23
21
|
data = JSON.parse(payload)
|
24
|
-
@consumer.call(data)
|
22
|
+
@consumer.new.call(data)
|
25
23
|
success = true
|
26
24
|
rescue StandardError => exception
|
27
25
|
logger.error "Error thrown in subscribe block"
|
@@ -34,7 +32,7 @@ module Watership
|
|
34
32
|
Bugsnag.notify(exception, data: {payload: data, retries: retries}) if defined?(Bugsnag)
|
35
33
|
|
36
34
|
new_data = data.merge({retries: retries+1})
|
37
|
-
Watership.enqueue!(name: @consumer
|
35
|
+
Watership.enqueue!(name: @consumer::QUEUE, message: new_data)
|
38
36
|
success = true
|
39
37
|
rescue Interrupt => exception
|
40
38
|
logger.error "Interrupt in subscribe block"
|
@@ -61,7 +59,10 @@ module Watership
|
|
61
59
|
channel.close
|
62
60
|
end
|
63
61
|
|
64
|
-
|
62
|
+
def bind(name, opts = {})
|
63
|
+
queue.bind(name, opts)
|
64
|
+
end
|
65
|
+
|
65
66
|
def ack_message(tag)
|
66
67
|
logger.info "Acking message"
|
67
68
|
channel.acknowledge(tag, false)
|
@@ -73,7 +74,7 @@ module Watership
|
|
73
74
|
end
|
74
75
|
|
75
76
|
def queue
|
76
|
-
@queue ||= channel.queue(@consumer
|
77
|
+
@queue ||= channel.queue(@consumer::QUEUE, @channel_opts)
|
77
78
|
end
|
78
79
|
|
79
80
|
def connection
|
data/lib/watership/version.rb
CHANGED
metadata
CHANGED
@@ -1,84 +1,86 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: watership
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.9.0pre
|
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-10-
|
11
|
+
date: 2014-10-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ~>
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '1.5'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - ~>
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.5'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: bunny
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: json
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
description: Wrapper around Bunny to better handle connection issues
|
70
70
|
email:
|
71
71
|
- git@turrean.com
|
72
|
-
executables:
|
72
|
+
executables:
|
73
|
+
- watership-consume
|
73
74
|
extensions: []
|
74
75
|
extra_rdoc_files: []
|
75
76
|
files:
|
76
|
-
- .gitignore
|
77
|
+
- ".gitignore"
|
77
78
|
- CHANGELOG.md
|
78
79
|
- Gemfile
|
79
80
|
- LICENSE.txt
|
80
81
|
- README.md
|
81
82
|
- Rakefile
|
83
|
+
- bin/watership-consume
|
82
84
|
- lib/watership.rb
|
83
85
|
- lib/watership/consumer.rb
|
84
86
|
- lib/watership/subscriber.rb
|
@@ -94,14 +96,14 @@ require_paths:
|
|
94
96
|
- lib
|
95
97
|
required_ruby_version: !ruby/object:Gem::Requirement
|
96
98
|
requirements:
|
97
|
-
- -
|
99
|
+
- - ">="
|
98
100
|
- !ruby/object:Gem::Version
|
99
101
|
version: '0'
|
100
102
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
103
|
requirements:
|
102
|
-
- -
|
104
|
+
- - ">"
|
103
105
|
- !ruby/object:Gem::Version
|
104
|
-
version:
|
106
|
+
version: 1.3.1
|
105
107
|
requirements: []
|
106
108
|
rubyforge_project:
|
107
109
|
rubygems_version: 2.2.2
|