delayed_job 4.0.2 → 4.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -13
- data/CHANGELOG.md +7 -0
- data/README.md +12 -7
- data/Rakefile +6 -1
- data/delayed_job.gemspec +5 -5
- data/lib/delayed/backend/base.rb +18 -20
- data/lib/delayed/backend/shared_spec.rb +139 -138
- data/lib/delayed/command.rb +75 -40
- data/lib/delayed/exceptions.rb +2 -1
- data/lib/delayed/lifecycle.rb +12 -11
- data/lib/delayed/message_sending.rb +9 -10
- data/lib/delayed/performable_mailer.rb +2 -2
- data/lib/delayed/performable_method.rb +2 -2
- data/lib/delayed/psych_ext.rb +29 -93
- data/lib/delayed/recipes.rb +5 -5
- data/lib/delayed/serialization/active_record.rb +11 -9
- data/lib/delayed/syck_ext.rb +3 -3
- data/lib/delayed/tasks.rb +5 -5
- data/lib/delayed/worker.rb +42 -42
- data/lib/generators/delayed_job/delayed_job_generator.rb +2 -3
- data/spec/delayed/backend/test.rb +22 -17
- data/spec/delayed/command_spec.rb +57 -0
- data/spec/helper.rb +25 -12
- data/spec/lifecycle_spec.rb +23 -15
- data/spec/message_sending_spec.rb +34 -34
- data/spec/performable_mailer_spec.rb +11 -11
- data/spec/performable_method_spec.rb +24 -26
- data/spec/psych_ext_spec.rb +12 -0
- data/spec/sample_jobs.rb +46 -18
- data/spec/test_backend_spec.rb +3 -3
- data/spec/worker_spec.rb +27 -27
- data/spec/yaml_ext_spec.rb +16 -16
- metadata +12 -8
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe 'Psych::Visitors::ToRuby', :if => defined?(Psych::Visitors::ToRuby) do
|
4
|
+
context BigDecimal do
|
5
|
+
it 'deserializes correctly' do
|
6
|
+
deserialized = YAML.load("--- !ruby/object:BigDecimal 18:0.1337E2\n...\n")
|
7
|
+
|
8
|
+
expect(deserialized).to be_an_instance_of(BigDecimal)
|
9
|
+
expect(deserialized).to eq(BigDecimal('13.37'))
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
data/spec/sample_jobs.rb
CHANGED
@@ -5,45 +5,73 @@ class NamedJob < Struct.new(:perform)
|
|
5
5
|
end
|
6
6
|
|
7
7
|
class SimpleJob
|
8
|
-
cattr_accessor :runs
|
9
|
-
|
8
|
+
cattr_accessor :runs
|
9
|
+
@runs = 0
|
10
|
+
def perform
|
11
|
+
self.class.runs += 1
|
12
|
+
end
|
10
13
|
end
|
11
14
|
|
12
15
|
class ErrorJob
|
13
|
-
cattr_accessor :runs
|
14
|
-
|
16
|
+
cattr_accessor :runs
|
17
|
+
@runs = 0
|
18
|
+
def perform
|
19
|
+
raise 'did not work'
|
20
|
+
end
|
15
21
|
end
|
16
22
|
|
17
23
|
class CustomRescheduleJob < Struct.new(:offset)
|
18
|
-
cattr_accessor :runs
|
19
|
-
|
20
|
-
def
|
24
|
+
cattr_accessor :runs
|
25
|
+
@runs = 0
|
26
|
+
def perform
|
27
|
+
raise 'did not work'
|
28
|
+
end
|
29
|
+
|
30
|
+
def reschedule_at(time, _attempts)
|
31
|
+
time + offset
|
32
|
+
end
|
21
33
|
end
|
22
34
|
|
23
35
|
class LongRunningJob
|
24
|
-
def perform
|
36
|
+
def perform
|
37
|
+
sleep 250
|
38
|
+
end
|
25
39
|
end
|
26
40
|
|
27
41
|
class OnPermanentFailureJob < SimpleJob
|
28
|
-
|
29
|
-
|
42
|
+
attr_writer :raise_error
|
43
|
+
|
44
|
+
def initialize
|
45
|
+
@raise_error = false
|
46
|
+
end
|
47
|
+
|
48
|
+
def failure
|
49
|
+
raise 'did not work' if @raise_error
|
50
|
+
end
|
51
|
+
|
52
|
+
def max_attempts
|
53
|
+
1
|
54
|
+
end
|
30
55
|
end
|
31
56
|
|
32
57
|
module M
|
33
58
|
class ModuleJob
|
34
|
-
cattr_accessor :runs
|
35
|
-
|
59
|
+
cattr_accessor :runs
|
60
|
+
@runs = 0
|
61
|
+
def perform
|
62
|
+
self.class.runs += 1
|
63
|
+
end
|
36
64
|
end
|
37
65
|
end
|
38
66
|
|
39
67
|
class CallbackJob
|
40
68
|
cattr_accessor :messages
|
41
69
|
|
42
|
-
def enqueue(
|
70
|
+
def enqueue(_job)
|
43
71
|
self.class.messages << 'enqueue'
|
44
72
|
end
|
45
73
|
|
46
|
-
def before(
|
74
|
+
def before(_job)
|
47
75
|
self.class.messages << 'before'
|
48
76
|
end
|
49
77
|
|
@@ -51,19 +79,19 @@ class CallbackJob
|
|
51
79
|
self.class.messages << 'perform'
|
52
80
|
end
|
53
81
|
|
54
|
-
def after(
|
82
|
+
def after(_job)
|
55
83
|
self.class.messages << 'after'
|
56
84
|
end
|
57
85
|
|
58
|
-
def success(
|
86
|
+
def success(_job)
|
59
87
|
self.class.messages << 'success'
|
60
88
|
end
|
61
89
|
|
62
|
-
def error(
|
90
|
+
def error(_job, error)
|
63
91
|
self.class.messages << "error: #{error.class}"
|
64
92
|
end
|
65
93
|
|
66
|
-
def failure(
|
94
|
+
def failure(_job)
|
67
95
|
self.class.messages << 'failure'
|
68
96
|
end
|
69
97
|
end
|
data/spec/test_backend_spec.rb
CHANGED
@@ -3,9 +3,9 @@ require 'helper'
|
|
3
3
|
describe Delayed::Backend::Test::Job do
|
4
4
|
it_should_behave_like 'a delayed_job backend'
|
5
5
|
|
6
|
-
describe
|
7
|
-
it
|
8
|
-
job =
|
6
|
+
describe '#reload' do
|
7
|
+
it 'causes the payload object to be reloaded' do
|
8
|
+
job = 'foo'.delay.length
|
9
9
|
o = job.payload_object
|
10
10
|
expect(o.object_id).not_to eq(job.reload.payload_object.object_id)
|
11
11
|
end
|
data/spec/worker_spec.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
3
|
describe Delayed::Worker do
|
4
|
-
describe
|
4
|
+
describe 'backend=' do
|
5
5
|
before do
|
6
6
|
@clazz = Class.new
|
7
7
|
Delayed::Worker.backend = @clazz
|
@@ -11,30 +11,30 @@ describe Delayed::Worker do
|
|
11
11
|
Delayed::Worker.backend = :test
|
12
12
|
end
|
13
13
|
|
14
|
-
it
|
14
|
+
it 'sets the Delayed::Job constant to the backend' do
|
15
15
|
expect(Delayed::Job).to eq(@clazz)
|
16
16
|
end
|
17
17
|
|
18
|
-
it
|
18
|
+
it 'sets backend with a symbol' do
|
19
19
|
Delayed::Worker.backend = :test
|
20
20
|
expect(Delayed::Worker.backend).to eq(Delayed::Backend::Test::Job)
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
|
-
describe
|
24
|
+
describe 'job_say' do
|
25
25
|
before do
|
26
26
|
@worker = Delayed::Worker.new
|
27
27
|
@job = double('job', :id => 123, :name => 'ExampleJob')
|
28
28
|
end
|
29
29
|
|
30
|
-
it
|
30
|
+
it 'logs with job name and id' do
|
31
31
|
expect(@worker).to receive(:say).
|
32
32
|
with('Job ExampleJob (id=123) message', Delayed::Worker::DEFAULT_LOG_LEVEL)
|
33
33
|
@worker.job_say(@job, 'message')
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
|
-
context
|
37
|
+
context 'worker read-ahead' do
|
38
38
|
before do
|
39
39
|
@read_ahead = Delayed::Worker.read_ahead
|
40
40
|
end
|
@@ -43,19 +43,19 @@ describe Delayed::Worker do
|
|
43
43
|
Delayed::Worker.read_ahead = @read_ahead
|
44
44
|
end
|
45
45
|
|
46
|
-
it
|
46
|
+
it 'reads five jobs' do
|
47
47
|
expect(Delayed::Job).to receive(:find_available).with(anything, 5, anything).and_return([])
|
48
48
|
Delayed::Job.reserve(Delayed::Worker.new)
|
49
49
|
end
|
50
50
|
|
51
|
-
it
|
51
|
+
it 'reads a configurable number of jobs' do
|
52
52
|
Delayed::Worker.read_ahead = 15
|
53
53
|
expect(Delayed::Job).to receive(:find_available).with(anything, Delayed::Worker.read_ahead, anything).and_return([])
|
54
54
|
Delayed::Job.reserve(Delayed::Worker.new)
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
58
|
-
context
|
58
|
+
context 'worker exit on complete' do
|
59
59
|
before do
|
60
60
|
Delayed::Worker.exit_on_complete = true
|
61
61
|
end
|
@@ -64,15 +64,15 @@ describe Delayed::Worker do
|
|
64
64
|
Delayed::Worker.exit_on_complete = false
|
65
65
|
end
|
66
66
|
|
67
|
-
it
|
67
|
+
it 'exits the loop when no jobs are available' do
|
68
68
|
worker = Delayed::Worker.new
|
69
|
-
Timeout
|
69
|
+
Timeout.timeout(2) do
|
70
70
|
worker.start
|
71
71
|
end
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
75
|
-
context
|
75
|
+
context 'worker job reservation' do
|
76
76
|
before do
|
77
77
|
Delayed::Worker.exit_on_complete = true
|
78
78
|
end
|
@@ -81,34 +81,34 @@ describe Delayed::Worker do
|
|
81
81
|
Delayed::Worker.exit_on_complete = false
|
82
82
|
end
|
83
83
|
|
84
|
-
it
|
84
|
+
it 'handles error during job reservation' do
|
85
85
|
expect(Delayed::Job).to receive(:reserve).and_raise(Exception)
|
86
86
|
Delayed::Worker.new.work_off
|
87
87
|
end
|
88
88
|
|
89
|
-
it
|
89
|
+
it 'gives up after 10 backend failures' do
|
90
90
|
expect(Delayed::Job).to receive(:reserve).exactly(10).times.and_raise(Exception)
|
91
91
|
worker = Delayed::Worker.new
|
92
92
|
9.times { worker.work_off }
|
93
93
|
expect(lambda { worker.work_off }).to raise_exception Delayed::FatalBackendError
|
94
94
|
end
|
95
95
|
|
96
|
-
it
|
96
|
+
it 'allows the backend to attempt recovery from reservation errors' do
|
97
97
|
expect(Delayed::Job).to receive(:reserve).and_raise(Exception)
|
98
98
|
expect(Delayed::Job).to receive(:recover_from).with(instance_of(Exception))
|
99
99
|
Delayed::Worker.new.work_off
|
100
100
|
end
|
101
101
|
end
|
102
102
|
|
103
|
-
context
|
103
|
+
context '#say' do
|
104
104
|
before(:each) do
|
105
105
|
@worker = Delayed::Worker.new
|
106
106
|
@worker.name = 'ExampleJob'
|
107
107
|
@worker.logger = double('job')
|
108
108
|
time = Time.now
|
109
109
|
allow(Time).to receive(:now).and_return(time)
|
110
|
-
@text =
|
111
|
-
@worker_name =
|
110
|
+
@text = 'Job executed'
|
111
|
+
@worker_name = '[Worker(ExampleJob)]'
|
112
112
|
@expected_time = time.strftime('%FT%T%z')
|
113
113
|
end
|
114
114
|
|
@@ -116,7 +116,7 @@ describe Delayed::Worker do
|
|
116
116
|
@worker.logger = nil
|
117
117
|
end
|
118
118
|
|
119
|
-
shared_examples_for
|
119
|
+
shared_examples_for 'a worker which logs on the correct severity' do |severity|
|
120
120
|
it "logs a message on the #{severity[:level].upcase} level given a string" do
|
121
121
|
expect(@worker.logger).to receive(:send).
|
122
122
|
with(severity[:level], "#{@expected_time}: #{@worker_name} #{@text}")
|
@@ -130,19 +130,19 @@ describe Delayed::Worker do
|
|
130
130
|
end
|
131
131
|
end
|
132
132
|
|
133
|
-
severities = [
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
133
|
+
severities = [{:index => 0, :level => 'debug'},
|
134
|
+
{:index => 1, :level => 'info'},
|
135
|
+
{:index => 2, :level => 'warn'},
|
136
|
+
{:index => 3, :level => 'error'},
|
137
|
+
{:index => 4, :level => 'fatal'},
|
138
|
+
{:index => 5, :level => 'unknown'}]
|
139
139
|
severities.each do |severity|
|
140
|
-
it_behaves_like
|
140
|
+
it_behaves_like 'a worker which logs on the correct severity', severity
|
141
141
|
end
|
142
142
|
|
143
143
|
it "logs a message on the default log's level" do
|
144
144
|
expect(@worker.logger).to receive(:send).
|
145
|
-
with(
|
145
|
+
with('info', "#{@expected_time}: #{@worker_name} #{@text}")
|
146
146
|
@worker.say(@text, Delayed::Worker::DEFAULT_LOG_LEVEL)
|
147
147
|
end
|
148
148
|
end
|
data/spec/yaml_ext_spec.rb
CHANGED
@@ -1,35 +1,35 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
|
-
describe
|
4
|
-
it
|
5
|
-
expect
|
3
|
+
describe 'YAML' do
|
4
|
+
it 'autoloads classes' do
|
5
|
+
expect do
|
6
6
|
yaml = "--- !ruby/class Autoloaded::Clazz\n"
|
7
7
|
expect(YAML.load(yaml)).to eq(Autoloaded::Clazz)
|
8
|
-
|
8
|
+
end.not_to raise_error
|
9
9
|
end
|
10
10
|
|
11
|
-
it
|
12
|
-
expect
|
11
|
+
it 'autoloads the class of a struct' do
|
12
|
+
expect do
|
13
13
|
yaml = "--- !ruby/class Autoloaded::Struct\n"
|
14
14
|
expect(YAML.load(yaml)).to eq(Autoloaded::Struct)
|
15
|
-
|
15
|
+
end.not_to raise_error
|
16
16
|
end
|
17
17
|
|
18
|
-
it
|
19
|
-
expect
|
20
|
-
yaml =
|
18
|
+
it 'autoloads the class for the instance of a struct' do
|
19
|
+
expect do
|
20
|
+
yaml = '--- !ruby/struct:Autoloaded::InstanceStruct {}'
|
21
21
|
expect(YAML.load(yaml).class).to eq(Autoloaded::InstanceStruct)
|
22
|
-
|
22
|
+
end.not_to raise_error
|
23
23
|
end
|
24
24
|
|
25
|
-
it
|
26
|
-
expect
|
25
|
+
it 'autoloads the class for the instance' do
|
26
|
+
expect do
|
27
27
|
yaml = "--- !ruby/object:Autoloaded::InstanceClazz {}\n"
|
28
28
|
expect(YAML.load(yaml).class).to eq(Autoloaded::InstanceClazz)
|
29
|
-
|
29
|
+
end.not_to raise_error
|
30
30
|
end
|
31
31
|
|
32
|
-
it
|
33
|
-
expect{ YAML.load(YAML.dump(
|
32
|
+
it 'does not throw an uninitialized constant Syck::Syck when using YAML.load with poorly formed yaml' do
|
33
|
+
expect { YAML.load(YAML.dump('foo: *bar')) }.not_to raise_error
|
34
34
|
end
|
35
35
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: delayed_job
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.0.
|
4
|
+
version: 4.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brandon Keepers
|
@@ -15,26 +15,26 @@ authors:
|
|
15
15
|
autorequire:
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
|
-
date: 2014-
|
18
|
+
date: 2014-09-04 00:00:00.000000000 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: activesupport
|
22
22
|
requirement: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '3.0'
|
27
|
-
- - <
|
27
|
+
- - "<"
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
version: '4.2'
|
30
30
|
type: :runtime
|
31
31
|
prerelease: false
|
32
32
|
version_requirements: !ruby/object:Gem::Requirement
|
33
33
|
requirements:
|
34
|
-
- -
|
34
|
+
- - ">="
|
35
35
|
- !ruby/object:Gem::Version
|
36
36
|
version: '3.0'
|
37
|
-
- - <
|
37
|
+
- - "<"
|
38
38
|
- !ruby/object:Gem::Version
|
39
39
|
version: '4.2'
|
40
40
|
description: Delayed_job (or DJ) encapsulates the common pattern of asynchronously
|
@@ -85,12 +85,14 @@ files:
|
|
85
85
|
- spec/autoloaded/instance_struct.rb
|
86
86
|
- spec/autoloaded/struct.rb
|
87
87
|
- spec/delayed/backend/test.rb
|
88
|
+
- spec/delayed/command_spec.rb
|
88
89
|
- spec/delayed/serialization/test.rb
|
89
90
|
- spec/helper.rb
|
90
91
|
- spec/lifecycle_spec.rb
|
91
92
|
- spec/message_sending_spec.rb
|
92
93
|
- spec/performable_mailer_spec.rb
|
93
94
|
- spec/performable_method_spec.rb
|
95
|
+
- spec/psych_ext_spec.rb
|
94
96
|
- spec/sample_jobs.rb
|
95
97
|
- spec/test_backend_spec.rb
|
96
98
|
- spec/worker_spec.rb
|
@@ -105,12 +107,12 @@ require_paths:
|
|
105
107
|
- lib
|
106
108
|
required_ruby_version: !ruby/object:Gem::Requirement
|
107
109
|
requirements:
|
108
|
-
- -
|
110
|
+
- - ">="
|
109
111
|
- !ruby/object:Gem::Version
|
110
112
|
version: '0'
|
111
113
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
112
114
|
requirements:
|
113
|
-
- -
|
115
|
+
- - ">="
|
114
116
|
- !ruby/object:Gem::Version
|
115
117
|
version: '0'
|
116
118
|
requirements: []
|
@@ -125,12 +127,14 @@ test_files:
|
|
125
127
|
- spec/autoloaded/instance_struct.rb
|
126
128
|
- spec/autoloaded/struct.rb
|
127
129
|
- spec/delayed/backend/test.rb
|
130
|
+
- spec/delayed/command_spec.rb
|
128
131
|
- spec/delayed/serialization/test.rb
|
129
132
|
- spec/helper.rb
|
130
133
|
- spec/lifecycle_spec.rb
|
131
134
|
- spec/message_sending_spec.rb
|
132
135
|
- spec/performable_mailer_spec.rb
|
133
136
|
- spec/performable_method_spec.rb
|
137
|
+
- spec/psych_ext_spec.rb
|
134
138
|
- spec/sample_jobs.rb
|
135
139
|
- spec/test_backend_spec.rb
|
136
140
|
- spec/worker_spec.rb
|