lev 7.0.3 → 7.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: 39058e1cbfa410f404d73fa99f6cdb4fd101bdb6
4
- data.tar.gz: 7b9f5c3e3366f9915f3c1bb16086c6b5c0c20a41
3
+ metadata.gz: d9ea57006e876643c43923721b4df56584b6c7a7
4
+ data.tar.gz: 90fa8d60e6c1a7229d143614b1b74e0470c92458
5
5
  SHA512:
6
- metadata.gz: 388f7e4f202994665ddcc1881081526859d3e059738e2f60af3ebed416f4e4615a9d75bac3d588fd84780e9f331a60d0f8b2a4c4477b11eb1caebce301177af4
7
- data.tar.gz: 756b6ee8991ee1b3e92912c496c1d766be58122b8c9efaefff90edcbab267c610b5453ebe837ab6b46d18130e66d15bcac984d30e760bb5d63e4f2e54b49ff11
6
+ metadata.gz: 2b7a39b7c78d35f1b62d61a36607fea7fec2fe9d3416e3fd1442322967e0fd932bdbbca65b6ec9cc0e48073b14bdc9e559293559e6fc6e2c6dec29588f047362
7
+ data.tar.gz: e1938a24304b4d9c3673098aa48e9c0dd13b70839a7e6c72e84b79800da9c68bb64e24fce187f3ce3545ab893c716a98447338117eddc67395ac6b8477ad88d5
@@ -1,21 +1,37 @@
1
1
  module Lev
2
2
  module ActiveJob
3
3
  class Base < Lev.configuration.job_class
4
+ attr_accessor(:provider_job_id) unless respond_to?(:provider_job_id)
5
+
4
6
  def self.perform_later(routine_class, *args, &block)
5
7
  queue_as routine_class.active_job_queue
6
- args.push(routine_class.to_s)
7
8
 
8
- # Create a new status object and push its ID on to the arguments so that
9
- # in `perform` it can be used to retrieve the status when the routine is
10
- # initialized.
9
+ # Create a new status object
11
10
  status = Lev::create_status
11
+
12
+ # Push the routine class name on to the arguments
13
+ # so that we can run the correct routine in `perform`
14
+ args.push(routine_class.to_s)
15
+
16
+ # Push the status's ID on to the arguments so that in `perform`
17
+ # it can be used to retrieve the status when the routine is initialized
12
18
  args.push(status.id)
13
19
 
20
+ # Set the job_name
21
+ status.set_job_name(routine_class.name)
22
+
14
23
  # In theory we'd mark as queued right after the call to super, but this messes
15
- # up when the activejob adapter runs the job right away
24
+ # up when the activejob adapter runs the job right away (inline mode)
16
25
  status.queued!
17
- super(*args, &block)
18
26
 
27
+ # Queue up the job and set the provider_job_id
28
+ # For delayed_job, requires either Rails 5 or
29
+ # http://stackoverflow.com/questions/29855768/rails-4-2-get-delayed-job-id-from-active-job
30
+ provider_job_id = super(*args, &block).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
19
35
  status.id
20
36
  end
21
37
 
@@ -22,6 +22,9 @@ class Lev::NullStatus
22
22
  # within routines; routines should not be using other query methods to check
23
23
  # their own status (they should know it), with the exception of `kill_requested?`
24
24
 
25
+ def set_job_name(*); end
26
+ def set_job_args(*); end
27
+ def set_provider_job_id(*); end
25
28
  def set_progress(*); end
26
29
  def save(*); end
27
30
  def add_error(*); end
@@ -1,3 +1,3 @@
1
1
  module Lev
2
- VERSION = "7.0.3"
2
+ VERSION = "7.1.0"
3
3
  end
@@ -3,8 +3,8 @@ require 'spec_helper'
3
3
  describe Lev::Routine do
4
4
 
5
5
  before do
6
- stub_const 'RaiseError', Class.new
7
- RaiseError.class_eval {
6
+ stub_const 'RaiseRuntimeError', Class.new
7
+ RaiseRuntimeError.class_eval {
8
8
  lev_routine
9
9
  def exec
10
10
  raise 'error message'
@@ -18,12 +18,20 @@ describe Lev::Routine do
18
18
  unknown_method_call
19
19
  end
20
20
  }
21
+
22
+ stub_const 'RaiseArgumentError', Class.new
23
+ RaiseArgumentError.class_eval {
24
+ lev_routine
25
+ def exec
26
+ raise ArgumentError, 'your argument is invalid', caller
27
+ end
28
+ }
21
29
  end
22
30
 
23
31
  it "raised errors should propagate" do
24
32
  expect{
25
33
  RaiseArgumentError.call
26
- }.to raise_error
34
+ }.to raise_error(ArgumentError)
27
35
  end
28
36
 
29
37
  it "raised StandardErrors should propagate" do
@@ -59,7 +67,7 @@ describe Lev::Routine do
59
67
 
60
68
  expect {
61
69
  SpecialFatalErrorOption.call
62
- }.to raise_error
70
+ }.to raise_error(Lev::FatalError)
63
71
 
64
72
  expect {
65
73
  NoFatalErrorOption.call
@@ -106,7 +114,7 @@ describe Lev::Routine do
106
114
  it 'raises an exception on fatal_error if configured' do
107
115
  expect {
108
116
  RaiseFatalError.call
109
- }.to raise_error
117
+ }.to raise_error(Lev::FatalError)
110
118
 
111
119
  begin
112
120
  RaiseFatalError.call
@@ -4,7 +4,8 @@
4
4
  # loaded once.
5
5
  #
6
6
  # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
-
7
+ require 'bundler'
8
+ Bundler.require('default')
8
9
  require 'active_job'
9
10
 
10
11
  ActiveJob::Base.queue_adapter = :test
@@ -25,6 +26,7 @@ require 'lev'
25
26
  require 'byebug'
26
27
 
27
28
  require 'transaction_retry'
29
+
28
30
  TransactionRetry.apply_activerecord_patch
29
31
 
30
32
  Dir[(File.expand_path('../support', __FILE__)) + ("/**/*.rb")].each { |f| require f }
@@ -4,9 +4,10 @@ class StatusedRoutine
4
4
  lev_routine
5
5
 
6
6
  protected
7
- def exec
7
+
8
+ def exec(*args)
8
9
  status.set_progress(9, 10)
9
- status.save({'hi' => 'there'})
10
+ status.save('hi' => 'there')
10
11
  fatal_error(code: 'blah', message: 'hi')
11
12
  end
12
13
  end
@@ -15,11 +16,23 @@ RSpec.describe 'Statused Routines' do
15
16
 
16
17
  before { Lev::Jobba.use_jobba }
17
18
 
19
+ let(:routine_class) { StatusedRoutine }
20
+ let(:args) { ['some arg'] }
21
+ let(:status_id) { routine_class.perform_later(*args) }
22
+ let(:status) { Jobba::Status.find(status_id) }
23
+
18
24
  context 'in a routine' do
19
- it 'queues the job object on queue' do
20
- id = StatusedRoutine.perform_later
21
- status = Jobba::Status.find(id)
25
+ it 'sets the job_name on the status' do
26
+ expect(status.job_name).to eq routine_class.name
27
+ end
28
+
29
+ it 'sets the provider_job_id on the status' do
30
+ expect_any_instance_of(Lev::ActiveJob::Base).to receive(:provider_job_id).and_return(42)
31
+
32
+ expect(status.provider_job_id).to eq 42
33
+ end
22
34
 
35
+ it 'sets the status to queued' do
23
36
  expect(status).to be_queued
24
37
  end
25
38
 
@@ -29,12 +42,10 @@ RSpec.describe 'Statused Routines' do
29
42
 
30
43
  it 'sets job to started when called' do
31
44
  expect_any_instance_of(Jobba::Status).to receive(:started!)
32
- StatusedRoutine.perform_later
45
+ routine_class.perform_later
33
46
  end
34
47
 
35
48
  it 'completes the status object on completion, returning other data' do
36
- id = StatusedRoutine.perform_later
37
- status = Jobba::Status.find(id)
38
49
  expect(status).to be_failed
39
50
  expect(status.progress).to eq(0.9)
40
51
  expect(status.errors).to contain_exactly(
@@ -35,7 +35,7 @@ RSpec.describe 'Transactions' do
35
35
  it 'rolls back on exceptions' do
36
36
  expect {
37
37
  RollBackTransactions.call
38
- }.to raise_error
38
+ }.to raise_error(RuntimeError)
39
39
 
40
40
  expect(Model.count).to eq(0)
41
41
  end
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: 7.0.3
4
+ version: 7.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: 2016-08-08 00:00:00.000000000 Z
11
+ date: 2017-04-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -198,14 +198,14 @@ dependencies:
198
198
  requirements:
199
199
  - - ">="
200
200
  - !ruby/object:Gem::Version
201
- version: '0'
201
+ version: '1.5'
202
202
  type: :development
203
203
  prerelease: false
204
204
  version_requirements: !ruby/object:Gem::Requirement
205
205
  requirements:
206
206
  - - ">="
207
207
  - !ruby/object:Gem::Version
208
- version: '0'
208
+ version: '1.5'
209
209
  - !ruby/object:Gem::Dependency
210
210
  name: rails
211
211
  requirement: !ruby/object:Gem::Requirement
@@ -292,7 +292,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
292
292
  version: '0'
293
293
  requirements: []
294
294
  rubyforge_project:
295
- rubygems_version: 2.4.8
295
+ rubygems_version: 2.6.6
296
296
  signing_key:
297
297
  specification_version: 4
298
298
  summary: Ride the rails but don't touch them.