watership 0.9.0pre4 → 0.9.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- MjdhOGViYzhhYWQ3NWYzY2IxYjY4ZTVhZDM1MjNmZTAyODg1Mjk0MA==
5
- data.tar.gz: !binary |-
6
- YWFkNzk2Y2M1YTllZWE5N2Y3MTFiODkxMDYzMDZlMWQ1ZjIxZWVkYQ==
2
+ SHA1:
3
+ metadata.gz: 7835bdb83a4a8f081115ca051b4062364866f29e
4
+ data.tar.gz: 266209a3236afba8a2a377beac5b27caa1763f67
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- Y2RhNmQwZWNjNjM2OTQ5MDZhYTQ2YmQwZjBjNzM0OWJlYzU3ODhlZDI2ZWYw
10
- MzJmMDAwODNjNWYxMzk2NDU4YTg4MTMwOGRlNDE1NTAxOTU5MjU4MWIzMjBh
11
- YzAxMzc2NmMyOTE4YmQ0Y2Q1ZThlNDcwNDY1YTdjNzc0MWZjMWI=
12
- data.tar.gz: !binary |-
13
- ZjExNGMxNWI0NDczZGQ5NTdhMThiM2U2NTEwOGU0YjI4OWFiZmI0OTFlMGEw
14
- MzM0MDM4ZjJmZWM5Y2RiYWU5Y2JkZjcxY2NlNDgwOGY3Yjc2NTk1YjA2MGQ3
15
- N2YzMmExNGYwODM1NTgzN2M3MDE4NjljMzUzYTY5ZWFiYWUwNGI=
6
+ metadata.gz: a824cfd74887e18631ab6ac0a1fdebdbf1fd4132ad96e140a410d053a97a011fdcae4b0349f9b560d371c943f19c13aca5565dd16bbe256369de53d7465985b0
7
+ data.tar.gz: 1dd1d097d932e7f547b69bff93bdf283a4086126a4bd5d45560c38cdb56e223b41c9b662e90175766148b6b949a191e1b003e8b04d229d1b8573ec587fd3ae6b
data/lib/watership.rb CHANGED
@@ -12,6 +12,7 @@ module Watership
12
12
 
13
13
  CLEAR_CONNECTION_EXCEPTIONS = [
14
14
  Bunny::ConnectionError,
15
+ Bunny::ClientTimeout,
15
16
  Timeout::Error
16
17
  ]
17
18
 
@@ -60,10 +61,13 @@ module Watership
60
61
  registered.fetch(name.to_sym).enqueue(opts)
61
62
  end
62
63
 
64
+ class << self
65
+ alias enqueue! enqueue
66
+ end
67
+
63
68
  class Client
64
69
  def initialize(uri, env)
65
- @uri = uri
66
- @env = env
70
+ @uri, @env = uri, env
67
71
  end
68
72
 
69
73
  def enqueue(options = {})
@@ -78,7 +82,6 @@ module Watership
78
82
 
79
83
  queue = connect_with_queue(name, options)
80
84
  queue.publish(JSON.generate(message))
81
-
82
85
  rescue *CONNECTION_EXCEPTIONS => exception
83
86
  fallback.call if fallback
84
87
  notify(exception)
@@ -15,33 +15,34 @@ module Watership
15
15
 
16
16
  def consume
17
17
  Thread.abort_on_exception = true
18
+ queue = create_queue
18
19
  @concurrency.times do
19
- queue.subscribe(@queue_opts) 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")
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")
28
30
 
29
- retries = data["retries"] || 0
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
30
44
 
31
- Airbrake.notify(exception) if defined?(Airbrake)
32
- Bugsnag.notify(exception, data: {payload: data, retries: retries}) if defined?(Bugsnag)
33
-
34
- new_data = data.merge({retries: retries+1})
35
- Watership.enqueue!(name: @consumer::QUEUE, message: new_data)
36
- success = true
37
- rescue Interrupt => exception
38
- logger.error "Interrupt in subscribe block"
39
- logger.warn "Stopped gracefully."
40
- ensure
41
- if success
42
- ack_message(delivery_info.delivery_tag)
43
- else
44
- reject_message(delivery_info.delivery_tag)
45
+ clear_active_record_connections
45
46
  end
46
47
  end
47
48
  end
@@ -60,7 +61,7 @@ module Watership
60
61
  end
61
62
 
62
63
  def bind(name, opts = {})
63
- queue.bind(name, opts)
64
+ create_queue.bind(name, opts)
64
65
  end
65
66
 
66
67
  def ack_message(tag)
@@ -73,8 +74,8 @@ module Watership
73
74
  channel.reject(tag, requeue)
74
75
  end
75
76
 
76
- def queue
77
- @queue ||= channel.queue(@consumer::QUEUE, @channel_opts)
77
+ def create_queue
78
+ channel.queue(@consumer::QUEUE, @channel_opts)
78
79
  end
79
80
 
80
81
  def connection
@@ -83,14 +84,29 @@ module Watership
83
84
 
84
85
  def channel
85
86
  @channel ||= begin
86
- c = connection.create_channel(nil, @concurrency)
87
- c.prefetch(@prefetch)
88
- c
87
+ created_channel = connection.create_channel(nil, @concurrency)
88
+ created_channel.prefetch(@prefetch)
89
+ created_channel
89
90
  end
90
91
  end
91
92
 
93
+ def enqueue(message)
94
+ create_queue.publish(JSON.generate(message))
95
+ end
96
+
97
+ def notify(exception, data)
98
+ Airbrake.notify(exception) if defined?(Airbrake)
99
+ Bugsnag.notify(exception, data: data) if defined?(Bugsnag)
100
+ end
101
+
92
102
  def logger
93
103
  @logger ||= defined?(Rails) ? Rails.logger : Logger.new(STDOUT)
94
104
  end
105
+
106
+ def clear_active_record_connections
107
+ if defined?(::ActiveRecord::Base) && ::ActiveRecord::Base.respond_to?(:clear_active_connections!)
108
+ ::ActiveRecord::Base.clear_active_connections!
109
+ end
110
+ end
95
111
  end
96
112
  end
@@ -1,3 +1,3 @@
1
1
  module Watership
2
- VERSION = "0.9.0pre4"
2
+ VERSION = "0.9.2"
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.0pre4
4
+ version: 0.9.2
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-03 00:00:00.000000000 Z
11
+ date: 2014-11-04 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: 1.3.1
106
+ version: '0'
107
107
  requirements: []
108
108
  rubyforge_project:
109
109
  rubygems_version: 2.2.2