watership 0.9.2 → 0.9.3pre

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,15 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 7835bdb83a4a8f081115ca051b4062364866f29e
4
- data.tar.gz: 266209a3236afba8a2a377beac5b27caa1763f67
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ NTQ4OGY2NWM3NjJlYjU3M2EwNzk2OTVkNjgzMWRmNWI5NGQxMWYzOQ==
5
+ data.tar.gz: !binary |-
6
+ MjVhYzA3Y2I2NDc3YTdhYWY0NDEzNmU5NjM5ODE3MzE4NzMwYjBiOA==
5
7
  SHA512:
6
- metadata.gz: a824cfd74887e18631ab6ac0a1fdebdbf1fd4132ad96e140a410d053a97a011fdcae4b0349f9b560d371c943f19c13aca5565dd16bbe256369de53d7465985b0
7
- data.tar.gz: 1dd1d097d932e7f547b69bff93bdf283a4086126a4bd5d45560c38cdb56e223b41c9b662e90175766148b6b949a191e1b003e8b04d229d1b8573ec587fd3ae6b
8
+ metadata.gz: !binary |-
9
+ Yzc5NjI1NGI4NjZkNWEzNmI3MzFiOTM3Y2U5MzljODA4NWU2ZjU1ODBjY2U1
10
+ MGM5NDQzMGU5ZjBjN2RjYjYzNWMyYzVhZGFjZWVjZjNhZTM4OGZhZTQwNDAw
11
+ NmU0ZDFlODBlOGJhMmQwNWMyNWM5M2RkYWY4M2RlOTNlNjAyMWU=
12
+ data.tar.gz: !binary |-
13
+ ZDc5ODVlYTkzMTc2MTlhN2VlMmZkNWZkOTcyNWVmMjhhZDM2ODM5MThhYjU2
14
+ ZmZmZTgxNGE1MTRlOTM3NDQ2MDUzMWY1NWUwODg3ZTY3YjIyZWQyYTUyMTA3
15
+ NDIxNWFlNjcyN2RlNTAwNmY4OGU4OTE4NTQ3YmJlM2IyMDRhNjg=
@@ -9,52 +9,42 @@ module Watership
9
9
  @url = url
10
10
  @prefetch = channel_options.delete(:prefetch) || Integer(ENV.fetch("RABBIT_CONSUMER_PREFETCH", 200))
11
11
  @concurrency = channel_options.delete(:concurrency) || 1
12
- @channel_opts = {durable: true}.merge(channel_options)
13
- @queue_opts = {block: false, manual_ack: true}.merge(queue_options)
12
+ @forever = channel_options.delete(:forever) || true
13
+ @channel_opts = { durable: true }.merge(channel_options)
14
+ @queue_opts = { block: false, manual_ack: true }.merge(queue_options)
14
15
  end
15
16
 
16
17
  def consume
17
- Thread.abort_on_exception = true
18
18
  queue = create_queue
19
- @concurrency.times do
20
- Thread.new do
21
- queue.subscribe(@queue_opts.dup) do |delivery_info, properties, payload|
22
- begin
23
- data = JSON.parse(payload)
24
- @consumer.new.call(data)
25
- success = true
26
- rescue StandardError => exception
27
- logger.error "Error thrown in subscribe block"
28
- logger.error exception.message
29
- logger.error exception.backtrace.join("\n")
30
-
31
- retries = data["retries"] || 0
32
- notify(exception, { payload: data, retries: retries })
33
- enqueue(data.merge(retries: (retries + 1)))
34
- success = true
35
- rescue Interrupt => exception
36
- logger.error "Interrupt in subscribe block"
37
- logger.warn "Stopped gracefully."
38
- ensure
39
- if success
40
- ack_message(delivery_info.delivery_tag)
41
- else
42
- reject_message(delivery_info.delivery_tag)
43
- end
44
-
45
- clear_active_record_connections
46
- end
19
+ queue.subscribe(@queue_opts.dup) do |delivery_info, properties, payload|
20
+ begin
21
+ data = JSON.parse(payload)
22
+ @consumer.new.call(data)
23
+ success = true
24
+ rescue StandardError => exception
25
+ logger.error "Error thrown in subscribe block"
26
+ logger.error exception.message
27
+ logger.error exception.backtrace.join("\n")
28
+
29
+ retries = data["retries"] || 0
30
+ notify(exception, { payload: data, retries: retries })
31
+ enqueue(data.merge(retries: (retries + 1)))
32
+ success = true
33
+ rescue Interrupt => exception
34
+ logger.error "Interrupt in subscribe block"
35
+ logger.warn "Stopped gracefully."
36
+ ensure
37
+ if success
38
+ ack_message(delivery_info.delivery_tag)
39
+ else
40
+ reject_message(delivery_info.delivery_tag)
47
41
  end
42
+
43
+ clear_active_record_connections
48
44
  end
49
45
  end
50
46
 
51
- # sleep forever
52
- sleeping_thread = Thread.new { sleep }
53
- Signal.trap("TERM") do
54
- sleeping_thread.terminate
55
- end
56
- sleeping_thread.join
57
- rescue Interrupt
47
+ self.class.sleep_forever if @forever
58
48
  ensure
59
49
  logger.info "Closing Channel"
60
50
  channel.close
@@ -108,5 +98,14 @@ module Watership
108
98
  ::ActiveRecord::Base.clear_active_connections!
109
99
  end
110
100
  end
101
+
102
+ def self.sleep_forever
103
+ sleepy_thread = Thread.new { sleep }
104
+ Signal.trap("TERM") do
105
+ sleepy_thread.terminate
106
+ end
107
+ sleepy_thread.join
108
+ rescue Interrupt
109
+ end
111
110
  end
112
111
  end
@@ -1,3 +1,3 @@
1
1
  module Watership
2
- VERSION = "0.9.2"
2
+ VERSION = "0.9.3pre"
3
3
  end
metadata CHANGED
@@ -1,69 +1,69 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: watership
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.2
4
+ version: 0.9.3pre
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-04 00:00:00.000000000 Z
11
+ date: 2014-11-12 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
@@ -74,7 +74,7 @@ executables:
74
74
  extensions: []
75
75
  extra_rdoc_files: []
76
76
  files:
77
- - ".gitignore"
77
+ - .gitignore
78
78
  - CHANGELOG.md
79
79
  - Gemfile
80
80
  - LICENSE.txt
@@ -96,14 +96,14 @@ require_paths:
96
96
  - lib
97
97
  required_ruby_version: !ruby/object:Gem::Requirement
98
98
  requirements:
99
- - - ">="
99
+ - - ! '>='
100
100
  - !ruby/object:Gem::Version
101
101
  version: '0'
102
102
  required_rubygems_version: !ruby/object:Gem::Requirement
103
103
  requirements:
104
- - - ">="
104
+ - - ! '>'
105
105
  - !ruby/object:Gem::Version
106
- version: '0'
106
+ version: 1.3.1
107
107
  requirements: []
108
108
  rubyforge_project:
109
109
  rubygems_version: 2.2.2