sneakers 2.2.0 → 2.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: eb490f1549a3348a646ec90b63a8af53e7085896
4
- data.tar.gz: a74285f7ae5b6e64158cc6cef77d2846be90a585
3
+ metadata.gz: 562f562a5bb003fdf3d00ae2a37eaf8e3201f80c
4
+ data.tar.gz: 922e09184bfd33fd91aac65f3ca109a98f85ad46
5
5
  SHA512:
6
- metadata.gz: 8836ba87a2032d77e0a8c8713c00c2d00ca53da2d8bae2d3613a2a2f1fcbdf72e6487bd1b45996aafca2e8138e0ea3971beb142eae9706e726a1d32d14669886
7
- data.tar.gz: e5c54fb937fdd219c570554a4577ba225a090b0fa5772396c0eeea39207d3176a8bdb880a92d8675e979335d0459f1cb156a40acfeeb231efa0300eb6f4c1d4f
6
+ metadata.gz: 5261d1b94c18d35bd051313865eec1612a74cfa1b4b5d340f942eec951f3f8fc0cf1f5f169c47ac48a57ef9bbd5aee62baffcdef8eb18741542fe64ce1beaa14
7
+ data.tar.gz: fbcb6831ef3fa9f5fd28a6ac12c1ef8a83e12aed46e0834a128fc43e752c6bc7f435dfc51fa5cd3307b168ca7b130bc6be0dd702738ceda8e00390d8488e9cf7
@@ -1,3 +1,8 @@
1
+ env:
2
+ - INTEGRATION_LOG=1 INTEGRATION=1
3
+ services:
4
+ - rabbitmq
5
+ - redis-server
1
6
  language: ruby
2
7
  rvm:
3
8
  - 2.2
data/README.md CHANGED
@@ -54,7 +54,11 @@ gem 'json'
54
54
  gem 'redis'
55
55
  ```
56
56
 
57
- And a worker
57
+ How do we add a worker? Firstly create a file and name it as `boot.rb`
58
+ then create a worker named as `Processor`.
59
+
60
+ > touch boot.rb
61
+
58
62
 
59
63
  ```ruby
60
64
  require 'sneakers'
@@ -79,17 +83,6 @@ class Processor
79
83
  end
80
84
  ```
81
85
 
82
- We'll count errors and error types with Redis. As an example, make a message that looks like this:
83
-
84
- ```javascript
85
- {
86
- "type": "error",
87
- "message": "HALP!",
88
- "error": "CODE001"
89
- }
90
- ```
91
-
92
-
93
86
  Let's test it out quickly from the command line:
94
87
 
95
88
 
@@ -99,8 +92,17 @@ $ sneakers work Processor --require boot.rb
99
92
 
100
93
  We just told Sneakers to spawn a worker named `Processor`, but first `--require` a file that we dedicate to setting up environment, including workers and what-not.
101
94
 
102
- If you go to your RabbitMQ admin now, you'll see a new queue named `logs` was created. Push a couple messages, and this is the output you should see at your terminal.
95
+ If you go to your RabbitMQ admin now, you'll see a new queue named `logs` was created. Push a couple messages like below:
96
+
97
+ ```javascript
98
+ {
99
+ "type": "error",
100
+ "message": "HALP!",
101
+ "error": "CODE001"
102
+ }
103
+ ```
103
104
 
105
+ And this is the output you should see at your terminal.
104
106
 
105
107
  ```
106
108
  2013-10-11T19:26:36Z p-4718 t-ovqgyb31o DEBUG: [worker-logs:1:213mmy][#<Thread:0x007fae6b05cc58>][logs][{:prefetch=>10, :durable=>true, :ack=>true, :heartbeat_interval=>2, :exchange=>"sneakers"}] Working off: log log
@@ -109,8 +111,8 @@ If you go to your RabbitMQ admin now, you'll see a new queue named `logs` was cr
109
111
  2013-10-11T19:26:40Z p-4719 t-ovqgyrx8g INFO: log log
110
112
  ```
111
113
 
112
- And redis will show this:
113
114
 
115
+ We'll count errors and error types with Redis.
114
116
 
115
117
  ``` shell-session
116
118
  $ redis-cli monitor
@@ -77,7 +77,7 @@ module Sneakers
77
77
  redacted.merge! to_hash
78
78
 
79
79
  # redact passwords
80
- redacted[:amqp] = redacted[:amqp].sub(/(?<=\Aamqp:\/)[^@]+(?=@)/, "<redacted>")
80
+ redacted[:amqp] = redacted[:amqp].sub(/(?<=\Aamqp:\/)[^@]+(?=@)/, "<redacted>") if redacted.has_key?(:amqp)
81
81
  return redacted.inspect_without_redaction
82
82
  end
83
83
  alias_method :inspect_without_redaction, :inspect
@@ -1,3 +1,3 @@
1
1
  module Sneakers
2
- VERSION = "2.2.0"
2
+ VERSION = "2.2.1"
3
3
  end
@@ -22,6 +22,10 @@ Gem::Specification.new do |gem|
22
22
  gem.add_dependency 'thread', '~> 0.1.7'
23
23
  gem.add_dependency 'thor'
24
24
 
25
+ # for integration environment (see .travis.yml and integration_spec)
26
+ gem.add_development_dependency 'rabbitmq_http_api_client'
27
+ gem.add_development_dependency 'redis'
28
+
25
29
  gem.add_development_dependency 'rr'
26
30
  gem.add_development_dependency 'ruby-prof'
27
31
  gem.add_development_dependency 'nokogiri'
@@ -0,0 +1,15 @@
1
+ require 'sneakers'
2
+ require 'thread'
3
+ require 'redis'
4
+
5
+ $redis = Redis.new
6
+
7
+ class IntegrationWorker
8
+ include Sneakers::Worker
9
+
10
+ def work(msg)
11
+ $redis.incr(self.class.queue_name)
12
+ ack!
13
+ end
14
+ end
15
+
@@ -0,0 +1,107 @@
1
+ require 'spec_helper'
2
+ require 'sneakers'
3
+ require 'sneakers/runner'
4
+ require 'fixtures/integration_worker'
5
+
6
+ require "rabbitmq/http/client"
7
+
8
+
9
+ describe "integration" do
10
+ describe 'first' do
11
+ before :each do
12
+ skip unless ENV['INTEGRATION']
13
+ prepare
14
+ end
15
+
16
+ def integration_log(msg)
17
+ puts msg if ENV['INTEGRATION_LOG']
18
+ end
19
+
20
+ def prepare
21
+ # clean up all integration queues; admin interface must be installed
22
+ # in integration env
23
+ begin
24
+ admin = RabbitMQ::HTTP::Client.new("http://127.0.0.1:15672/", username: "guest", password: "guest")
25
+ qs = admin.list_queues
26
+ qs.each do |q|
27
+ name = q.name
28
+ if name.start_with? 'integration_'
29
+ admin.delete_queue('/', name)
30
+ integration_log "cleaning up #{name}."
31
+ end
32
+ end
33
+ rescue
34
+ puts "Rabbitmq admin seems to not exist? you better be running this on Travis or Docker. proceeding.\n#{$!}"
35
+ end
36
+
37
+
38
+ Sneakers.configure
39
+ Sneakers.logger.level = Logger::ERROR
40
+
41
+ # configure integration worker on a random generated queue
42
+ random_queue = "integration_#{rand(10**36).to_s(36)}"
43
+
44
+ @redis = Redis.new
45
+ @redis.del(random_queue)
46
+ IntegrationWorker.from_queue(random_queue)
47
+ end
48
+
49
+ def assert_all_accounted_for(opts)
50
+ integration_log 'waiting for publishes to stabilize (5s).'
51
+ sleep 5
52
+
53
+ integration_log "polling for changes (max #{opts[:within_sec]}s)."
54
+ pid = opts[:pid]
55
+ opts[:within_sec].times do
56
+ sleep 1
57
+ count = @redis.get(opts[:queue]).to_i
58
+ if count == opts[:jobs]
59
+ integration_log "#{count} jobs accounted for successfully."
60
+ Process.kill("TERM", pid)
61
+ sleep 1
62
+ return
63
+ end
64
+ end
65
+
66
+ integration_log "failed test. killing off workers."
67
+ Process.kill("TERM", pid)
68
+ sleep 1
69
+ fail "incomplete!"
70
+ end
71
+
72
+ def start_worker(w)
73
+ integration_log "starting workers."
74
+ r = Sneakers::Runner.new([w])
75
+ pid = fork {
76
+ r.run
77
+ }
78
+
79
+ integration_log "waiting for workers to stabilize (5s)."
80
+ sleep 5
81
+
82
+ pid
83
+ end
84
+
85
+ it 'should pull down 100 jobs from a real queue' do
86
+ job_count = 100
87
+
88
+ pid = start_worker(IntegrationWorker)
89
+
90
+ integration_log "publishing..."
91
+ p = Sneakers::Publisher.new
92
+ job_count.times do |i|
93
+ p.publish("m #{i}", to_queue: IntegrationWorker.queue_name)
94
+ end
95
+
96
+ assert_all_accounted_for(
97
+ queue: IntegrationWorker.queue_name,
98
+ pid: pid,
99
+ within_sec: 15,
100
+ jobs: job_count,
101
+ )
102
+ end
103
+
104
+ end
105
+ end
106
+
107
+
@@ -29,16 +29,37 @@ describe Sneakers::RunnerConfig do
29
29
  let(:logger) { Logger.new("logtest.log") }
30
30
  let(:runner_config) { Sneakers::Runner.new([]).instance_variable_get("@runnerconfig") }
31
31
 
32
- before { Sneakers.configure(log: logger) }
33
32
 
34
33
 
35
- describe "#reload_config!" do
36
- it "must not have :log key" do
37
- runner_config.reload_config!.has_key?(:log).must_equal false
34
+ describe "with a connection" do
35
+ before { Sneakers.configure(log: logger, connection: Object.new) }
36
+
37
+ describe "#reload_config!" do
38
+ it "does not throw exception" do
39
+ runner_config.reload_config!
40
+ end
41
+
42
+ it "must not have :log key" do
43
+ runner_config.reload_config!.has_key?(:log).must_equal false
44
+ end
45
+
46
+ it "must have :logger key as an instance of Logger" do
47
+ runner_config.reload_config![:logger].is_a?(Logger).must_equal true
48
+ end
38
49
  end
50
+ end
51
+
52
+ describe "without a connection" do
53
+ before { Sneakers.configure(log: logger) }
39
54
 
40
- it "must have :logger key as an instance of Logger" do
41
- runner_config.reload_config![:logger].is_a?(Logger).must_equal true
55
+ describe "#reload_config!" do
56
+ it "must not have :log key" do
57
+ runner_config.reload_config!.has_key?(:log).must_equal false
58
+ end
59
+
60
+ it "must have :logger key as an instance of Logger" do
61
+ runner_config.reload_config![:logger].is_a?(Logger).must_equal true
62
+ end
42
63
  end
43
64
  end
44
65
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sneakers
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0
4
+ version: 2.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dotan Nahum
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-09 00:00:00.000000000 Z
11
+ date: 2015-09-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: serverengine
@@ -66,6 +66,34 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rabbitmq_http_api_client
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: redis
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
69
97
  - !ruby/object:Gem::Dependency
70
98
  name: rr
71
99
  requirement: !ruby/object:Gem::Requirement
@@ -216,7 +244,6 @@ extra_rdoc_files: []
216
244
  files:
217
245
  - ".gitignore"
218
246
  - ".travis.yml"
219
- - CHANGELOG.md
220
247
  - Gemfile
221
248
  - Guardfile
222
249
  - LICENSE.txt
@@ -254,11 +281,13 @@ files:
254
281
  - lib/sneakers/worker.rb
255
282
  - lib/sneakers/workergroup.rb
256
283
  - sneakers.gemspec
284
+ - spec/fixtures/integration_worker.rb
257
285
  - spec/fixtures/require_worker.rb
258
286
  - spec/sneakers/cli_spec.rb
259
287
  - spec/sneakers/concerns/logging_spec.rb
260
288
  - spec/sneakers/concerns/metrics_spec.rb
261
289
  - spec/sneakers/configuration_spec.rb
290
+ - spec/sneakers/integration_spec.rb
262
291
  - spec/sneakers/publisher_spec.rb
263
292
  - spec/sneakers/queue_spec.rb
264
293
  - spec/sneakers/runner_spec.rb
@@ -291,11 +320,13 @@ signing_key:
291
320
  specification_version: 4
292
321
  summary: Fast background processing framework for Ruby and RabbitMQ
293
322
  test_files:
323
+ - spec/fixtures/integration_worker.rb
294
324
  - spec/fixtures/require_worker.rb
295
325
  - spec/sneakers/cli_spec.rb
296
326
  - spec/sneakers/concerns/logging_spec.rb
297
327
  - spec/sneakers/concerns/metrics_spec.rb
298
328
  - spec/sneakers/configuration_spec.rb
329
+ - spec/sneakers/integration_spec.rb
299
330
  - spec/sneakers/publisher_spec.rb
300
331
  - spec/sneakers/queue_spec.rb
301
332
  - spec/sneakers/runner_spec.rb
@@ -1,20 +0,0 @@
1
- # 0.1.0, Not released yet
2
-
3
- + Added newrelic stats reporter (@arielze)
4
- + Added explicit routing_key at queue (@arielze)
5
- + Depracating self-daemonization (@jondot)
6
- + updating bunny (@michaelklishin)
7
- + Fix reference in publisher (@sergei-matheson)
8
- + Allow binding of multiple routing keys (@SebastianEdwards)
9
- + added work_with_params for advanced handling of work items with amqp
10
- headers. (#12)
11
- + Sneakers.not_environmental! will no disable auto-environment discovery.
12
- (#15)
13
-
14
-
15
-
16
-
17
- # 0.0.7
18
-
19
- + Sneakers core.
20
-