lev 8.0.0 → 8.1.0

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: 23ac8b75438c4dcc055ba30a3df6862646138cb9
4
- data.tar.gz: 244bc1d7505e6dd29e84412f241cb1bde0cb82d0
3
+ metadata.gz: 10396668754e61bf873103c7b939507c6797ada7
4
+ data.tar.gz: 4c3d23e16f566c7f8f10acc9c2c53f692ddda0b0
5
5
  SHA512:
6
- metadata.gz: a1a19da74d6ddd287fba67e6f7caf05d52651d1a572b29a9500e835ebc83654d3a1a63102b8a7e775de30429f9810d64bb335c55fb0a275cf9ef107b0451f93d
7
- data.tar.gz: 90c37a45bbba09d725ec5ceda5661706d9b579885741309dd6f15b53ea3499fea2df7cb02b536fd17a3ce8484bf93bddf652f2ed6675a94207c91fe68921de79
6
+ metadata.gz: d44e4de024146fdaae53a3524177d17968836337ba6db82abe53ddcc9a0ec939d89585d902232d410cc123d746a085ac5a144e68aaafb9a53463c405d0279856
7
+ data.tar.gz: a24eefc3365c7181178b8bd04218335fd2d84f17087a01fd3d825c6b99e6c73e4acfa4c1e70e6cca6842db65fe1310c65608abc3a7a025574ccd5a72a950ba11
@@ -1,49 +1,2 @@
1
- module Lev
2
- module ActiveJob
3
- class Base < Lev.configuration.job_class
4
- attr_accessor(:provider_job_id) unless respond_to?(:provider_job_id)
5
-
6
- def self.perform_later(routine_class, *args, &block)
7
- # Create a new status object
8
- status = Lev::create_status
9
-
10
- # Push the routine class name on to the arguments
11
- # so that we can run the correct routine in `perform`
12
- args.push(routine_class.to_s)
13
-
14
- # Push the status's ID on to the arguments so that in `perform`
15
- # it can be used to retrieve the status when the routine is initialized
16
- args.push(status.id)
17
-
18
- # Set the job_name
19
- status.set_job_name(routine_class.name)
20
-
21
- # In theory we'd mark as queued right after the call to super, but this messes
22
- # up when the activejob adapter runs the job right away (inline mode)
23
- status.queued!
24
-
25
- # Queue up the job and set the provider_job_id
26
- # For delayed_job, requires either Rails 5 or
27
- # http://stackoverflow.com/questions/29855768/rails-4-2-get-delayed-job-id-from-active-job
28
- provider_job_id = job_or_instantiate(*args, &block)
29
- .enqueue(routine_class.active_job_enqueue_options)
30
- .provider_job_id
31
- status.set_provider_job_id(provider_job_id) \
32
- if provider_job_id.present? && status.respond_to?(:set_provider_job_id)
33
-
34
- # Return the id of the status object
35
- status.id
36
- end
37
-
38
- def perform(*args, &block)
39
- # Pop arguments added by perform_later
40
- id = args.pop
41
- routine_class = Kernel.const_get(args.pop)
42
-
43
- routine_instance = routine_class.new(Lev::find_status(id))
44
-
45
- routine_instance.call(*args, &block)
46
- end
47
- end
48
- end
49
- end
1
+ require 'lev/active_job/base'
2
+ require 'lev/active_job/configured_job'
@@ -0,0 +1,49 @@
1
+ module Lev
2
+ module ActiveJob
3
+ class Base < Lev.configuration.job_class
4
+ attr_accessor(:provider_job_id) unless respond_to?(:provider_job_id)
5
+
6
+ def perform_later(routine_class, options, *args, &block)
7
+ # Create a new status object
8
+ status = Lev::create_status
9
+
10
+ # Push the routine class name on to the arguments
11
+ # so that we can run the correct routine in `perform`
12
+ args.push(routine_class.to_s)
13
+
14
+ # Push the status's ID on to the arguments so that in `perform`
15
+ # it can be used to retrieve the status when the routine is initialized
16
+ args.push(status.id)
17
+
18
+ # Set the job_name
19
+ status.set_job_name(routine_class.name)
20
+
21
+ # In theory we'd mark as queued right after the call to super, but this messes
22
+ # up when the activejob adapter runs the job right away (inline mode)
23
+ status.queued!
24
+
25
+ # Queue up the job and set the provider_job_id
26
+ # For delayed_job, requires either Rails 5 or
27
+ # http://stackoverflow.com/questions/29855768/rails-4-2-get-delayed-job-id-from-active-job
28
+ provider_job_id = self.class.send(:job_or_instantiate, *args, &block)
29
+ .enqueue(options)
30
+ .provider_job_id
31
+ status.set_provider_job_id(provider_job_id) \
32
+ if provider_job_id.present? && status.respond_to?(:set_provider_job_id)
33
+
34
+ # Return the id of the status object
35
+ status.id
36
+ end
37
+
38
+ def perform(*args, &block)
39
+ # Pop arguments added by perform_later
40
+ id = args.pop
41
+ routine_class = Kernel.const_get(args.pop)
42
+
43
+ routine_instance = routine_class.new(Lev::find_status(id))
44
+
45
+ routine_instance.call(*args, &block)
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,20 @@
1
+ module Lev
2
+ module ActiveJob
3
+ class ConfiguredJob
4
+ attr_reader :routine_class
5
+
6
+ def initialize(routine_class, options)
7
+ @routine_class = routine_class
8
+ @options = options
9
+ end
10
+
11
+ def options
12
+ routine_class.active_job_enqueue_options.merge(@options)
13
+ end
14
+
15
+ def perform_later(*args, &block)
16
+ Lev::ActiveJob::Base.new.perform_later(routine_class, options, *args, &block)
17
+ end
18
+ end
19
+ end
20
+ end
@@ -208,9 +208,13 @@ module Lev
208
208
  result.outputs.send(@express_output)
209
209
  end
210
210
 
211
+ def set(options)
212
+ Lev::ActiveJob::ConfiguredJob.new(self, options)
213
+ end
214
+
211
215
  def perform_later(*args, &block)
212
216
  # Delegate to a subclass of Lev::Routine::ActiveJob::Base
213
- Lev::ActiveJob::Base.perform_later(self, *args, &block)
217
+ Lev::ActiveJob::Base.new.perform_later(self, active_job_enqueue_options, *args, &block)
214
218
  end
215
219
 
216
220
  def active_job_enqueue_options
@@ -1,3 +1,3 @@
1
1
  module Lev
2
- VERSION = "8.0.0"
2
+ VERSION = "8.1.0"
3
3
  end
@@ -18,7 +18,7 @@ RSpec.describe 'ActiveJob routines' do
18
18
  }.to change { ActiveJob::Base.queue_adapter.enqueued_jobs.count }.by(1)
19
19
  end
20
20
 
21
- it 'can have the default queue overridden' do
21
+ it 'can have the default queue name overridden in the class definition' do
22
22
  ActiveJob::Base.queue_adapter.enqueued_jobs.clear
23
23
 
24
24
  LaterRoutine.perform_later
@@ -27,6 +27,16 @@ RSpec.describe 'ActiveJob routines' do
27
27
 
28
28
  expect(queue_name).to eq('something_else')
29
29
  end
30
+
31
+ it 'can have the default queue name overridden using the set method' do
32
+ ActiveJob::Base.queue_adapter.enqueued_jobs.clear
33
+
34
+ LaterRoutine.set(queue: 'whoa').perform_later
35
+
36
+ queue_name = ActiveJob::Base.queue_adapter.enqueued_jobs.first[:queue]
37
+
38
+ expect(queue_name).to eq('whoa')
39
+ end
30
40
  end
31
41
 
32
42
  context 'exception raised' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lev
3
3
  version: !ruby/object:Gem::Version
4
- version: 8.0.0
4
+ version: 8.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - JP Slavinsky
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-09-22 00:00:00.000000000 Z
11
+ date: 2018-02-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -232,6 +232,8 @@ files:
232
232
  - Rakefile
233
233
  - lib/lev.rb
234
234
  - lib/lev/active_job.rb
235
+ - lib/lev/active_job/base.rb
236
+ - lib/lev/active_job/configured_job.rb
235
237
  - lib/lev/better_active_model_errors.rb
236
238
  - lib/lev/delegate_to_routine.rb
237
239
  - lib/lev/error.rb
@@ -297,23 +299,23 @@ signing_key:
297
299
  specification_version: 4
298
300
  summary: Ride the rails but don't touch them.
299
301
  test_files:
300
- - spec/active_job_routines_spec.rb
301
- - spec/create_sprocket_spec.rb
302
- - spec/deep_merge_spec.rb
303
- - spec/delegates_to_spec.rb
304
- - spec/outputs_spec.rb
305
- - spec/paramify_handler_spec.rb
306
- - spec/routine_spec.rb
307
302
  - spec/spec_helper.rb
303
+ - spec/paramify_handler_spec.rb
308
304
  - spec/sprocket_handler_spec.rb
309
- - spec/sprocket_spec.rb
310
- - spec/statused_routines_spec.rb
311
- - spec/support/create_sprocket.rb
312
- - spec/support/delegated_routine.rb
313
- - spec/support/delegating_routine.rb
305
+ - spec/create_sprocket_spec.rb
306
+ - spec/delegates_to_spec.rb
307
+ - spec/transaction_spec.rb
308
+ - spec/deep_merge_spec.rb
309
+ - spec/support/paramify_handler_b.rb
310
+ - spec/support/sprocket_handler.rb
314
311
  - spec/support/jobba.rb
315
312
  - spec/support/paramify_handler_a.rb
316
- - spec/support/paramify_handler_b.rb
313
+ - spec/support/delegating_routine.rb
314
+ - spec/support/create_sprocket.rb
315
+ - spec/support/delegated_routine.rb
317
316
  - spec/support/sprocket.rb
318
- - spec/support/sprocket_handler.rb
319
- - spec/transaction_spec.rb
317
+ - spec/sprocket_spec.rb
318
+ - spec/outputs_spec.rb
319
+ - spec/routine_spec.rb
320
+ - spec/active_job_routines_spec.rb
321
+ - spec/statused_routines_spec.rb