roundhouse-x 0.2.0 → 0.3.1

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: e419459121a0e984bdeb39afef3442ff962a37a9
4
- data.tar.gz: 8781d7c6f13f23bdc40c2a30311ac73d26476b07
3
+ metadata.gz: 467e42604542c9f936577bc980fc0432b3a8aaa1
4
+ data.tar.gz: 5608c37e8253f723a3e89902a99ab6b1c64b94f9
5
5
  SHA512:
6
- metadata.gz: 5648e6e5e86ab1e55b5c5e1a6e6f3eb2f660ed7013dc67b9e6b6ebf9910ebf9e2f2b2a5f375b94528c44c9b54d61d4b61e2a3c57510211e1d7aba38e2054ac1b
7
- data.tar.gz: 0b8591db28a22914c1eb5e1c0ca65fc90988e6f3b91ac623f07c1c2cca86453f03396112696bce5b0ff64fb1d13592e061266407d30909114aa98258a210f63f
6
+ metadata.gz: 999609bebfdc6f4d22bdf15ddb41bc736086d660316509d14e7b18f7c1fdce6cee620cf462970531111ab6ac057f90bac8f232cd88ee6f5f544e69063f0859d0
7
+ data.tar.gz: ce01b38302d771bd73a96021733b45a45c7f21bc6c39c94965e467fa58362b8295784afda7dbcb13916a4f08b7899e215807f40f94416db23d85dd6a61ca952e
@@ -0,0 +1 @@
1
+ require 'roundhouse'
data/lib/roundhouse.rb CHANGED
@@ -74,9 +74,19 @@ module Roundhouse
74
74
  defined?(Roundhouse::CLI)
75
75
  end
76
76
 
77
- def self.redis(&block)
78
- raise ArgumentError, "requires a block" unless block
79
- redis_pool.with(&block)
77
+ def self.redis
78
+ raise ArgumentError, "requires a block" unless block_given?
79
+ redis_pool.with do |conn|
80
+ retryable = true
81
+ begin
82
+ yield conn
83
+ rescue Redis::CommandError => ex
84
+ #2550 Failover can cause the server to become a slave, need
85
+ # to disconnect and reopen the socket to get back to the master.
86
+ (conn.disconnect!; retryable = false; retry) if retryable && ex.message =~ /READONLY/
87
+ raise
88
+ end
89
+ end
80
90
  end
81
91
 
82
92
  def self.redis_pool
@@ -132,7 +132,7 @@ module Roundhouse
132
132
  # get handle to the underlying thread performing work for a processor
133
133
  # so we have it call us and tell us.
134
134
  def real_thread(proxy_id, thr)
135
- @threads[proxy_id] = thr
135
+ @threads[proxy_id] = thr if thr.alive?
136
136
  end
137
137
 
138
138
  PROCTITLES = [
@@ -132,6 +132,7 @@ module Roundhouse
132
132
 
133
133
  conn.multi do
134
134
  conn.del(TURNTABLE)
135
+ conn.del(IN_ROTATION)
135
136
  queue_len.each do |(q_id, len)|
136
137
  s = status[q_id].to_i
137
138
 
@@ -41,18 +41,20 @@ module Roundhouse
41
41
 
42
42
  @boss.async.real_thread(proxy_id, Thread.current)
43
43
 
44
- ack = true
44
+ ack = false
45
45
  begin
46
46
  msg = Roundhouse.load_json(msgstr)
47
- klass = msg['class'].constantize
47
+ klass = msg['class'.freeze].constantize
48
48
  worker = klass.new
49
- worker.jid = msg['jid']
49
+ worker.jid = msg['jid'.freeze]
50
50
 
51
51
  stats(worker, msg, queue) do
52
52
  Roundhouse.server_middleware.invoke(worker, msg, queue) do
53
- execute_job(worker, cloned(msg['args']))
53
+ ack = true
54
+ execute_job(worker, cloned(msg['args'.freeze]))
54
55
  end
55
56
  end
57
+ ack = true
56
58
  rescue Roundhouse::Shutdown
57
59
  # Had to force kill this job because it didn't finish
58
60
  # within the timeout. Don't acknowledge the work since
@@ -97,14 +99,16 @@ module Roundhouse
97
99
  end
98
100
  end
99
101
 
102
+ nowdate = Time.now.utc.strftime("%Y-%m-%d".freeze)
100
103
  begin
101
104
  yield
102
105
  rescue Exception
103
106
  retry_and_suppress_exceptions do
104
107
  failed = "stat:failed:#{Time.now.utc.to_date}"
108
+ failed = "stat:failed:#{nowdate}"
105
109
  Roundhouse.redis do |conn|
106
110
  conn.multi do
107
- conn.incrby("stat:failed", 1)
111
+ conn.incrby("stat:failed".freeze, 1)
108
112
  conn.incrby(failed, 1)
109
113
  conn.expire(failed, STATS_TIMEOUT)
110
114
  end
@@ -113,11 +117,11 @@ module Roundhouse
113
117
  raise
114
118
  ensure
115
119
  retry_and_suppress_exceptions do
116
- processed = "stat:processed:#{Time.now.utc.to_date}"
120
+ processed = "stat:processed:#{nowdate}"
117
121
  Roundhouse.redis do |conn|
118
122
  conn.multi do
119
123
  conn.hdel("#{identity}:workers", thread_identity)
120
- conn.incrby("stat:processed", 1)
124
+ conn.incrby("stat:processed".freeze, 1)
121
125
  conn.incrby(processed, 1)
122
126
  conn.expire(processed, STATS_TIMEOUT)
123
127
  end
@@ -1,3 +1,3 @@
1
1
  module Roundhouse
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.1"
3
3
  end
data/roundhouse.gemspec CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |gem|
18
18
  gem.add_dependency 'redis', '~> 3.2', '>= 3.2.1'
19
19
  gem.add_dependency 'redis-namespace', '~> 1.5', '>= 1.5.2'
20
20
  gem.add_dependency 'connection_pool', '~> 2.2', '>= 2.2.0'
21
- gem.add_dependency 'celluloid', '~> 0.17.0'
21
+ gem.add_dependency 'celluloid', '~> 0.17.2'
22
22
  gem.add_dependency 'json', '~> 1.0'
23
23
  gem.add_dependency 'wolverine', '~> 0.3.3'
24
24
  gem.add_development_dependency 'sinatra', '~> 1.4', '>= 1.4.6'
@@ -84,4 +84,24 @@ class TestRoundhouse < Roundhouse::Test
84
84
  assert_includes output, "ERROR"
85
85
  end
86
86
  end
87
+
88
+ describe 'redis connection' do
89
+ it 'does not continually retry' do
90
+ assert_raises Redis::CommandError do
91
+ Roundhouse.redis do |c|
92
+ raise Redis::CommandError, "READONLY You can't write against a read only slave."
93
+ end
94
+ end
95
+ end
96
+
97
+ it 'reconnects if connection is flagged as readonly' do
98
+ counts = []
99
+ Roundhouse.redis do |c|
100
+ counts << c.info['total_connections_received'].to_i
101
+ raise Redis::CommandError, "READONLY You can't write against a read only slave." if counts.size == 1
102
+ end
103
+ assert_equal 2, counts.size
104
+ assert_equal counts[0] + 1, counts[1]
105
+ end
106
+ end
87
107
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: roundhouse-x
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ho-Sheng Hsiao
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-08-31 00:00:00.000000000 Z
12
+ date: 2015-11-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: redis
@@ -77,14 +77,14 @@ dependencies:
77
77
  requirements:
78
78
  - - "~>"
79
79
  - !ruby/object:Gem::Version
80
- version: 0.17.0
80
+ version: 0.17.2
81
81
  type: :runtime
82
82
  prerelease: false
83
83
  version_requirements: !ruby/object:Gem::Requirement
84
84
  requirements:
85
85
  - - "~>"
86
86
  - !ruby/object:Gem::Version
87
- version: 0.17.0
87
+ version: 0.17.2
88
88
  - !ruby/object:Gem::Dependency
89
89
  name: json
90
90
  requirement: !ruby/object:Gem::Requirement
@@ -211,6 +211,7 @@ files:
211
211
  - lib/generators/roundhouse/templates/worker_spec.rb.erb
212
212
  - lib/generators/roundhouse/templates/worker_test.rb.erb
213
213
  - lib/generators/roundhouse/worker_generator.rb
214
+ - lib/roundhouse-x.rb
214
215
  - lib/roundhouse.rb
215
216
  - lib/roundhouse/actor.rb
216
217
  - lib/roundhouse/api.rb
@@ -384,7 +385,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
384
385
  version: '0'
385
386
  requirements: []
386
387
  rubyforge_project:
387
- rubygems_version: 2.4.5
388
+ rubygems_version: 2.4.5.1
388
389
  signing_key:
389
390
  specification_version: 4
390
391
  summary: Round-robin load-balanced background processing for Ruby
@@ -416,4 +417,3 @@ test_files:
416
417
  - test/test_util.rb
417
418
  - test/test_web.rb
418
419
  - test/test_web_helpers.rb
419
- has_rdoc: