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 +4 -4
- data/lib/lev/active_job.rb +22 -6
- data/lib/lev/null_status.rb +3 -0
- data/lib/lev/version.rb +1 -1
- data/spec/routine_spec.rb +13 -5
- data/spec/spec_helper.rb +3 -1
- data/spec/statused_routines_spec.rb +19 -8
- data/spec/transaction_spec.rb +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d9ea57006e876643c43923721b4df56584b6c7a7
|
4
|
+
data.tar.gz: 90fa8d60e6c1a7229d143614b1b74e0470c92458
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2b7a39b7c78d35f1b62d61a36607fea7fec2fe9d3416e3fd1442322967e0fd932bdbbca65b6ec9cc0e48073b14bdc9e559293559e6fc6e2c6dec29588f047362
|
7
|
+
data.tar.gz: e1938a24304b4d9c3673098aa48e9c0dd13b70839a7e6c72e84b79800da9c68bb64e24fce187f3ce3545ab893c716a98447338117eddc67395ac6b8477ad88d5
|
data/lib/lev/active_job.rb
CHANGED
@@ -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
|
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
|
|
data/lib/lev/null_status.rb
CHANGED
@@ -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
|
data/lib/lev/version.rb
CHANGED
data/spec/routine_spec.rb
CHANGED
@@ -3,8 +3,8 @@ require 'spec_helper'
|
|
3
3
|
describe Lev::Routine do
|
4
4
|
|
5
5
|
before do
|
6
|
-
stub_const '
|
7
|
-
|
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
|
data/spec/spec_helper.rb
CHANGED
@@ -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
|
-
|
7
|
+
|
8
|
+
def exec(*args)
|
8
9
|
status.set_progress(9, 10)
|
9
|
-
status.save(
|
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 '
|
20
|
-
|
21
|
-
|
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
|
-
|
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(
|
data/spec/transaction_spec.rb
CHANGED
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
|
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:
|
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: '
|
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: '
|
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.
|
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.
|