coney_island 0.11.0 → 0.11.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: 7cd453ef44683112b719619cb03fa5b998e1467c
4
- data.tar.gz: 78093b8c5e994216d65cdbc9c47c31b3643a8fea
3
+ metadata.gz: 9a2c8ec4f4899725ab76ece82b50bb13c9bfc1cb
4
+ data.tar.gz: 4f2dc9c0ce8897c03f05f880f507d794fa87208c
5
5
  SHA512:
6
- metadata.gz: 0144d626a9db36ff167fa8ddba08669138f4edbdf9e6f9cc42686d09626a2b2a303e7480579e88a379c72381a19de00d67db72404d95a999465a9fa34760de75
7
- data.tar.gz: 87ad04598f5b5eaf43a2c885ea8e062c77a98c76159a677ea7560e890f9cbc2a454b91b88c9828aa921f723643dbafb36d90ffa3b4c6b97ecef9ed55b09cd49a
6
+ metadata.gz: 0ef8d2beed8302ee04a4be2d0affacfb6e2803ff2eaaae1fd9802235daf6125ffc5f77271c42434b195afe09f10d362cf3a12e839e182863b0522d9f270e6dc3
7
+ data.tar.gz: e9526c3ccf4ce3aa5e178d606db9d5679ddced9d21c35b55557435935614d3071b4bbcc1119ae1ec2dfa746d4ab2e2d4e7f5d62e3197f84a4bbb81f0ee653108
data/lib/coney_island.rb CHANGED
@@ -2,8 +2,6 @@ module ConeyIsland
2
2
 
3
3
  ### BEGIN configuration
4
4
 
5
- BG_TIMEOUT_SECONDS = 30
6
-
7
5
  def self.amqp_connection
8
6
  @connection
9
7
  end
@@ -120,6 +118,10 @@ module ConeyIsland
120
118
  end
121
119
  end
122
120
 
121
+ def self.default_settings
122
+ { work_queue: 'default', timeout: 30, delay: 0 }
123
+ end
124
+
123
125
  end
124
126
 
125
127
  require 'coney_island/notifiers/honeybadger_notifier'
@@ -128,4 +130,4 @@ require 'coney_island/job'
128
130
  require 'coney_island/submitter'
129
131
  require 'coney_island/job_argument_error'
130
132
  require 'coney_island/railtie' if defined?(Rails)
131
- require 'coney_island/performer'
133
+ require 'coney_island/performer'
@@ -22,11 +22,14 @@ module ConeyIsland
22
22
  @retry_on_exception = args['retry_on_exception']
23
23
 
24
24
  @metadata = metadata
25
- if @klass.respond_to? :coney_island_settings
26
- @delay ||= @klass.coney_island_settings[:delay]
27
- @timeout ||= @klass.coney_island_settings[:timeout]
25
+
26
+ if @klass.included_modules.include?(Performer)
27
+ @delay ||= @klass.get_coney_settings[:delay]
28
+ @timeout ||= @klass.get_coney_settings[:timeout]
28
29
  end
29
- @timeout ||= BG_TIMEOUT_SECONDS
30
+
31
+ @timeout ||= ConeyIsland.default_settings[:timeout]
32
+
30
33
  if @instance_id.present?
31
34
  @object = @klass.find(@instance_id)
32
35
  elsif @singleton
@@ -107,4 +110,4 @@ module ConeyIsland
107
110
  end
108
111
 
109
112
  end
110
- end
113
+ end
@@ -3,6 +3,8 @@ module ConeyIsland
3
3
 
4
4
  def self.included(base)
5
5
  base.extend ClassMethods
6
+ # http://apidock.com/rails/Class/class_attribute
7
+ base.class_attribute :coney_island_settings
6
8
  end
7
9
 
8
10
  def method_missing(method_name, *args)
@@ -21,16 +23,25 @@ module ConeyIsland
21
23
 
22
24
  module ClassMethods
23
25
 
24
- def set_background_defaults(work_queue: nil, delay: nil, timeout: nil)
25
- self.coney_island_settings[:work_queue] = work_queue
26
- self.coney_island_settings[:delay] = delay
27
- self.coney_island_settings[:timeout] = timeout
26
+ # Sets inheritable class defaults for ConeyIsland.
27
+ # Valid options:
28
+ # :work_queue - use a named queue for this class.
29
+ # :delay - Delay execution of the job on the worker. The delay value is
30
+ # a number of seconds.
31
+ # :timeout - Timeout the job with retry. The timeout value is a number
32
+ # of seconds. By default ConeyIsland will retry 3 times before bailing
33
+ # out.
34
+ def set_background_defaults(options = {})
35
+ options = options.dup.symbolize_keys.slice(:work_queue, :delay, :timeout)
36
+ self.coney_island_settings = get_coney_settings.merge(options)
28
37
  end
29
38
 
30
- def coney_island_settings
31
- @coney_island_settings ||= {}
39
+ def get_coney_settings
40
+ self.coney_island_settings ||= ConeyIsland.default_settings
32
41
  end
33
42
 
43
+ protected
44
+
34
45
  def method_missing(method_name, *args)
35
46
  method_str = method_name.to_s
36
47
  if method_str =~ /.*_async$/
@@ -115,19 +115,22 @@ module ConeyIsland
115
115
  job_args['klass'] = klass_name
116
116
  job_args['method_name'] = method_name
117
117
  job_args.stringify_keys!
118
+ # Extract non job args
119
+ delay = job_args.delete 'delay'
120
+ work_queue = job_args.delete 'work_queue'
121
+ # Set class defaults if they exist
122
+ if klass.included_modules.include?(Performer)
123
+ delay ||= klass.get_coney_settings[:delay]
124
+ work_queue ||= klass.get_coney_settings[:work_queue]
125
+ end
126
+ # Set our own defaults if we still don't have any
127
+ work_queue ||= ConeyIsland.default_settings[:work_queue]
128
+ delay ||= ConeyIsland.default_settings[:delay]
129
+
118
130
  if @run_inline
119
131
  job = ConeyIsland::Job.new(nil, job_args)
120
132
  job.handle_job
121
133
  else
122
- work_queue = job_args.delete 'work_queue'
123
- if klass.respond_to? :coney_island_settings
124
- work_queue ||= klass.coney_island_settings[:work_queue]
125
- end
126
- work_queue ||= 'default'
127
- delay = job_args['delay']
128
- if klass.respond_to? :coney_island_settings
129
- delay ||= klass.coney_island_settings[:delay]
130
- end
131
134
  if delay && delay.to_i > 0
132
135
  @delay_queue[work_queue] ||= {}
133
136
  unless @delay_queue[work_queue][delay].present?
@@ -1,3 +1,3 @@
1
1
  module ConeyIsland
2
- VERSION = "0.11.0"
2
+ VERSION = "0.11.1"
3
3
  end
@@ -1,32 +1,64 @@
1
+ undefined method `pry' for #<Binding:0x007f08a9ff6dc0>
2
+ undefined method `pry' for #<Binding:0x007f08a9fd5120>
3
+ undefined method `pry' for #<Binding:0x007f08a9fb4bf0>
1
4
  ConeyIsland::Submitter.submit! about to iterate over this many jobs: 1
2
5
  Failed to connecto to RabbitMQ Attempt #1 time(s), trying again in 0 seconds...
3
6
  ConeyIsland::Submitter.submit! about to iterate over this many jobs: 1
4
7
  Failed to connecto to RabbitMQ Attempt #1 time(s), trying again in 0 seconds...
8
+ Failed to connecto to RabbitMQ Attempt #1 time(s), trying again in 0 seconds...
9
+ ConeyIsland::Submitter.submit! about to iterate over this many jobs: 1
10
+ Failed to connecto to RabbitMQ Attempt #1 time(s), trying again in 0 seconds...
11
+ ConeyIsland::Submitter.submit! about to iterate over this many jobs: 1
12
+ ConeyIsland::Submitter.submit! about to iterate over this many jobs: 1
13
+ Failed to connecto to RabbitMQ Attempt #1 time(s), trying again in 0 seconds...
14
+ Failed to connecto to RabbitMQ Attempt #1 time(s), trying again in 0 seconds...
15
+ ConeyIsland::Submitter.submit! about to iterate over this many jobs: 1
16
+ ConeyIsland::Submitter.submit! about to iterate over this many jobs: 1
17
+ Failed to connecto to RabbitMQ Attempt #1 time(s), trying again in 0 seconds...
18
+ Failed to connecto to RabbitMQ Attempt #1 time(s), trying again in 0 seconds...
19
+ ConeyIsland::Submitter.submit! about to iterate over this many jobs: 1
20
+ Failed to connecto to RabbitMQ Attempt #1 time(s), trying again in 0 seconds...
5
21
  ConeyIsland::Submitter.submit! about to iterate over this many jobs: 1
22
+ ConeyIsland::Submitter.submit! about to iterate over this many jobs: 1
23
+ Failed to connecto to RabbitMQ Attempt #1 time(s), trying again in 0 seconds...
6
24
  Failed to connecto to RabbitMQ Attempt #1 time(s), trying again in 0 seconds...
7
25
  ConeyIsland::Submitter.submit! about to iterate over this many jobs: 1
26
+ ConeyIsland::Submitter.submit! about to iterate over this many jobs: 1
8
27
  Failed to connecto to RabbitMQ Attempt #1 time(s), trying again in 0 seconds...
28
+ ConeyIsland::Submitter.submit! about to iterate over this many jobs: 1
9
29
  Failed to connecto to RabbitMQ Attempt #1 time(s), trying again in 0 seconds...
30
+ Failed to connecto to RabbitMQ Attempt #1 time(s), trying again in 0 seconds...
31
+ ConeyIsland::Submitter.submit! about to iterate over this many jobs: 1
10
32
  ConeyIsland::Submitter.submit! about to iterate over this many jobs: 1
11
33
  Failed to connecto to RabbitMQ Attempt #1 time(s), trying again in 0 seconds...
12
34
  ConeyIsland::Submitter.submit! about to iterate over this many jobs: 1
13
- undefined method `[]' for nil:NilClass
14
- undefined method `[]' for nil:NilClass
35
+ Failed to connecto to RabbitMQ Attempt #1 time(s), trying again in 0 seconds...
36
+ Failed to connecto to RabbitMQ Attempt #1 time(s), trying again in 0 seconds...
37
+ ConeyIsland::Submitter.submit! about to iterate over this many jobs: 1
15
38
  ConeyIsland::Submitter.submit! about to iterate over this many jobs: 1
16
39
  Failed to connecto to RabbitMQ Attempt #1 time(s), trying again in 0 seconds...
17
- undefined method `[]' for nil:NilClass
18
- undefined method `[]' for nil:NilClass
19
- undefined method `[]' for nil:NilClass
40
+ ConeyIsland::Submitter.submit! about to iterate over this many jobs: 1
20
41
  Failed to connecto to RabbitMQ Attempt #1 time(s), trying again in 0 seconds...
21
42
  ConeyIsland::Submitter.submit! about to iterate over this many jobs: 1
22
- undefined method `[]' for nil:NilClass
43
+ Failed to connecto to RabbitMQ Attempt #1 time(s), trying again in 0 seconds...
44
+ undefined method `publish' for nil:NilClass
45
+ undefined method `publish' for nil:NilClass
23
46
  ConeyIsland::Submitter.submit! about to iterate over this many jobs: 1
24
47
  Failed to connecto to RabbitMQ Attempt #1 time(s), trying again in 0 seconds...
48
+ undefined method `publish' for nil:NilClass
49
+ undefined method `publish' for nil:NilClass
50
+ undefined method `publish' for nil:NilClass
51
+ undefined method `publish' for nil:NilClass
25
52
  Failed to connecto to RabbitMQ Attempt #1 time(s), trying again in 0 seconds...
26
53
  ConeyIsland::Submitter.submit! about to iterate over this many jobs: 1
54
+ undefined method `publish' for nil:NilClass
55
+ undefined method `publish' for nil:NilClass
27
56
  Failed to connecto to RabbitMQ Attempt #1 time(s), trying again in 0 seconds...
28
57
  ConeyIsland::Submitter.submit! about to iterate over this many jobs: 1
58
+ mocked method :publish called with unexpected arguments ["{\"args\":[[]],\"klass\":\"TestModel\",\"method_name\":\"add_to_list\"}", {:routing_key=>"carousels.default"}]
59
+ ConeyIsland::Submitter.submit! about to iterate over this many jobs: 1
29
60
  Failed to connecto to RabbitMQ Attempt #1 time(s), trying again in 0 seconds...
30
61
  ConeyIsland::Submitter.submit! about to iterate over this many jobs: 1
62
+ Failed to connecto to RabbitMQ Attempt #1 time(s), trying again in 0 seconds...
31
63
  ConeyIsland::Submitter.submit! about to iterate over this many jobs: 1
32
64
  Failed to connecto to RabbitMQ Attempt #1 time(s), trying again in 0 seconds...
@@ -50,6 +50,34 @@ class PerformerTest < MiniTest::Test
50
50
  @exchange.verify
51
51
  ::PerformerTest.messages[:publish_hash][:routing_key].must_equal "carousels.boardwalk"
52
52
  end
53
+
54
+ it "inherits settings from a base class" do
55
+ @exchange = Minitest::Mock.new
56
+ def @exchange.publish(payload,options,&blk)
57
+ ::PerformerTest.messages[:publish_hash] = options
58
+ end
59
+ ConeyIsland::Submitter.stub(:handle_connection, nil) do
60
+ ConeyIsland::Submitter.stub(:exchange, @exchange) do
61
+ ConeyIsland::Submitter.stop_running_inline
62
+ ConeyIsland::Submitter.submit(MyInheritedPerformer, :perform, args: [], delay: 0)
63
+ end
64
+ end
65
+ @exchange.verify
66
+ ::PerformerTest.messages[:publish_hash][:routing_key].must_equal "carousels.this-other-queue"
67
+ end
68
+ end
69
+
70
+ describe "#get_coney_settings" do
71
+ it "inherits from the defaults" do
72
+ MySingleton.get_coney_settings.must_equal ConeyIsland.default_settings
73
+ end
74
+
75
+ it "is inheritable by subclasses" do
76
+ MyInheritedPerformer.get_coney_settings[:work_queue].must_equal 'this-other-queue'
77
+ # These come from the base class
78
+ MyInheritedPerformer.get_coney_settings[:timeout].must_equal 5
79
+ MyInheritedPerformer.get_coney_settings[:delay].must_equal 1
80
+ end
53
81
  end
54
82
 
55
83
  describe 'async methods' do
@@ -122,3 +150,6 @@ class MyPerformer
122
150
  end
123
151
  end
124
152
 
153
+ class MyInheritedPerformer < MyPerformer
154
+ set_background_defaults work_queue: "this-other-queue"
155
+ end
@@ -33,5 +33,52 @@ class SubmitterTest < MiniTest::Test
33
33
  end
34
34
  end
35
35
  end
36
+
37
+ def setup_mock(klass, method, args, expected_work_queue, work_queue=nil)
38
+ exchange = Minitest::Mock.new
39
+ options = { args: args }
40
+ options.merge! work_queue: work_queue if work_queue
41
+ exchange.expect :publish, nil, [String,{routing_key: "carousels.#{expected_work_queue}"}]
42
+ ConeyIsland::Submitter.stub(:handle_connection, nil) do
43
+ ConeyIsland::Submitter.stub(:exchange, exchange) do
44
+ ConeyIsland::Submitter.stop_running_inline
45
+ ConeyIsland::Submitter.submit(klass, method, options)
46
+ end
47
+ end
48
+ exchange
49
+ end
50
+
51
+ describe '.submit' do
52
+
53
+ it "is aware of default_settings" do
54
+ @exchange = setup_mock TestModel, :add_to_list, [[]], ConeyIsland.default_settings[:work_queue]
55
+ @exchange.verify
56
+ end
57
+
58
+ it "overrides defaults if passed in the args" do
59
+ @exchange = setup_mock TestModel, :add_to_list, [[]], 'my-queue', 'my-queue'
60
+ @exchange.verify
61
+ end
62
+ end
63
+
64
+ describe "when submitting a performer" do
65
+ it "inherits the settings from the performer set_background_defaults" do
66
+ @exchange = setup_mock DummyPerformer, :perform, nil, 'foo'
67
+ @exchange.verify
68
+ end
69
+
70
+ it "still allows overriding the set_background_defaults" do
71
+ @exchange = setup_mock DummyPerformer, :perform, nil, 'bar', 'bar'
72
+ @exchange.verify
73
+ end
74
+ end
75
+
36
76
  end
37
- end
77
+ end
78
+
79
+ class DummyPerformer
80
+ include ConeyIsland::Performer
81
+ set_background_defaults work_queue: 'foo'
82
+
83
+ def perform; end
84
+ end
data/test/test_helper.rb CHANGED
@@ -34,7 +34,6 @@ class MiniTest::Test
34
34
  end
35
35
 
36
36
  class TestModel
37
-
38
37
  def self.add_to_list(array)
39
38
  array.push "Added one!"
40
39
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: coney_island
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.0
4
+ version: 0.11.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Draut
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2015-04-04 00:00:00.000000000 Z
13
+ date: 2015-05-05 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rails
@@ -180,7 +180,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
180
180
  version: '0'
181
181
  requirements: []
182
182
  rubyforge_project:
183
- rubygems_version: 2.4.3
183
+ rubygems_version: 2.2.2
184
184
  signing_key:
185
185
  specification_version: 4
186
186
  summary: Want guaranteed delivery between your queue and your workers using ACKs?
@@ -188,44 +188,44 @@ summary: Want guaranteed delivery between your queue and your workers using ACKs
188
188
  features other background worker systems offer and you must have a ticket to ride
189
189
  at Coney Island.
190
190
  test_files:
191
- - test/coney_island_test.rb
192
- - test/dummy/app/assets/javascripts/application.js
193
191
  - test/dummy/app/assets/stylesheets/application.css
192
+ - test/dummy/app/assets/javascripts/application.js
194
193
  - test/dummy/app/controllers/application_controller.rb
195
194
  - test/dummy/app/helpers/application_helper.rb
196
195
  - test/dummy/app/views/layouts/application.html.erb
197
- - test/dummy/bin/bundle
198
- - test/dummy/bin/rails
199
- - test/dummy/bin/rake
200
- - test/dummy/config/application.rb
201
- - test/dummy/config/boot.rb
202
196
  - test/dummy/config/database.yml
203
- - test/dummy/config/environment.rb
204
- - test/dummy/config/environments/development.rb
205
- - test/dummy/config/environments/production.rb
206
- - test/dummy/config/environments/test.rb
207
- - test/dummy/config/initializers/assets.rb
197
+ - test/dummy/config/routes.rb
198
+ - test/dummy/config/secrets.yml
208
199
  - test/dummy/config/initializers/backtrace_silencers.rb
209
- - test/dummy/config/initializers/cookies_serializer.rb
210
- - test/dummy/config/initializers/filter_parameter_logging.rb
211
- - test/dummy/config/initializers/inflections.rb
212
200
  - test/dummy/config/initializers/mime_types.rb
201
+ - test/dummy/config/initializers/inflections.rb
202
+ - test/dummy/config/initializers/assets.rb
213
203
  - test/dummy/config/initializers/session_store.rb
204
+ - test/dummy/config/initializers/cookies_serializer.rb
214
205
  - test/dummy/config/initializers/wrap_parameters.rb
206
+ - test/dummy/config/initializers/filter_parameter_logging.rb
207
+ - test/dummy/config/application.rb
215
208
  - test/dummy/config/locales/en.yml
216
- - test/dummy/config/routes.rb
217
- - test/dummy/config/secrets.yml
218
- - test/dummy/config.ru
219
- - test/dummy/db/test.sqlite3
220
- - test/dummy/log/test.log
209
+ - test/dummy/config/environment.rb
210
+ - test/dummy/config/environments/production.rb
211
+ - test/dummy/config/environments/development.rb
212
+ - test/dummy/config/environments/test.rb
213
+ - test/dummy/config/boot.rb
221
214
  - test/dummy/public/404.html
222
215
  - test/dummy/public/422.html
223
- - test/dummy/public/500.html
224
216
  - test/dummy/public/favicon.ico
225
- - test/dummy/Rakefile
217
+ - test/dummy/public/500.html
218
+ - test/dummy/db/test.sqlite3
226
219
  - test/dummy/README.rdoc
227
- - test/job_test.rb
228
- - test/performer_test.rb
220
+ - test/dummy/bin/rails
221
+ - test/dummy/bin/rake
222
+ - test/dummy/bin/bundle
223
+ - test/dummy/config.ru
224
+ - test/dummy/log/test.log
225
+ - test/dummy/Rakefile
229
226
  - test/submitter_test.rb
227
+ - test/job_test.rb
230
228
  - test/test_helper.rb
231
229
  - test/worker_test.rb
230
+ - test/performer_test.rb
231
+ - test/coney_island_test.rb