inst-jobs 0.15.20 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/db/migrate/20101216224513_create_delayed_jobs.rb +2 -0
- data/db/migrate/20110208031356_add_delayed_jobs_tag.rb +2 -0
- data/db/migrate/20110426161613_add_delayed_jobs_max_attempts.rb +2 -0
- data/db/migrate/20110516225834_add_delayed_jobs_strand.rb +2 -0
- data/db/migrate/20110531144916_cleanup_delayed_jobs_indexes.rb +2 -0
- data/db/migrate/20110610213249_optimize_delayed_jobs.rb +2 -0
- data/db/migrate/20110831210257_add_delayed_jobs_next_in_strand.rb +2 -0
- data/db/migrate/20120510004759_delayed_jobs_delete_trigger_lock_for_update.rb +2 -0
- data/db/migrate/20120531150712_drop_psql_jobs_pop_fn.rb +2 -0
- data/db/migrate/20120607164022_delayed_jobs_use_advisory_locks.rb +2 -0
- data/db/migrate/20120607181141_index_jobs_on_locked_by.rb +2 -0
- data/db/migrate/20120608191051_add_jobs_run_at_index.rb +2 -0
- data/db/migrate/20120927184213_change_delayed_jobs_handler_to_text.rb +2 -0
- data/db/migrate/20140505215131_add_failed_jobs_original_job_id.rb +2 -0
- data/db/migrate/20140505215510_copy_failed_jobs_original_id.rb +2 -0
- data/db/migrate/20140505223637_drop_failed_jobs_original_id.rb +2 -0
- data/db/migrate/20140512213941_add_source_to_jobs.rb +2 -0
- data/db/migrate/20150807133223_add_max_concurrent_to_jobs.rb +2 -0
- data/db/migrate/20151123210429_add_expires_at_to_jobs.rb +2 -0
- data/db/migrate/20151210162949_improve_max_concurrent.rb +2 -0
- data/db/migrate/20161206323555_add_back_default_string_limits_jobs.rb +2 -0
- data/db/migrate/20181217155351_speed_up_max_concurrent_triggers.rb +2 -0
- data/db/migrate/20190726154743_make_critical_columns_not_null.rb +2 -0
- data/db/migrate/20200330230722_add_id_to_get_delayed_jobs_index.rb +2 -0
- data/db/migrate/20200824222232_speed_up_max_concurrent_delete_trigger.rb +97 -0
- data/db/migrate/20200825011002_add_strand_order_override.rb +128 -0
- data/lib/delayed/backend/active_record.rb +17 -7
- data/lib/delayed/backend/base.rb +34 -20
- data/lib/delayed/backend/redis/functions.rb +2 -0
- data/lib/delayed/backend/redis/job.rb +2 -0
- data/lib/delayed/batch.rb +5 -3
- data/lib/delayed/cli.rb +2 -0
- data/lib/delayed/core_ext/kernel.rb +9 -0
- data/lib/delayed/daemon.rb +2 -0
- data/lib/delayed/engine.rb +2 -0
- data/lib/delayed/job_tracking.rb +2 -0
- data/lib/delayed/lifecycle.rb +2 -0
- data/lib/delayed/log_tailer.rb +2 -0
- data/lib/delayed/logging.rb +2 -0
- data/lib/delayed/message_sending.rb +79 -104
- data/lib/delayed/performable_method.rb +24 -6
- data/lib/delayed/periodic.rb +6 -4
- data/lib/delayed/plugin.rb +2 -0
- data/lib/delayed/pool.rb +2 -0
- data/lib/delayed/server.rb +2 -0
- data/lib/delayed/server/helpers.rb +2 -0
- data/lib/delayed/settings.rb +7 -1
- data/lib/delayed/testing.rb +2 -0
- data/lib/delayed/version.rb +3 -1
- data/lib/delayed/work_queue/in_process.rb +2 -0
- data/lib/delayed/work_queue/parent_process.rb +2 -0
- data/lib/delayed/work_queue/parent_process/client.rb +2 -0
- data/lib/delayed/work_queue/parent_process/server.rb +3 -1
- data/lib/delayed/worker.rb +3 -1
- data/lib/delayed/worker/consul_health_check.rb +3 -1
- data/lib/delayed/worker/health_check.rb +2 -0
- data/lib/delayed/worker/null_health_check.rb +2 -0
- data/lib/delayed/worker/process_helper.rb +2 -0
- data/lib/delayed/yaml_extensions.rb +2 -0
- data/lib/delayed_job.rb +4 -0
- data/lib/inst-jobs.rb +2 -0
- data/spec/active_record_job_spec.rb +4 -6
- data/spec/delayed/cli_spec.rb +2 -0
- data/spec/delayed/daemon_spec.rb +2 -0
- data/spec/delayed/message_sending_spec.rb +51 -0
- data/spec/delayed/server_spec.rb +2 -4
- data/spec/delayed/settings_spec.rb +2 -0
- data/spec/delayed/work_queue/in_process_spec.rb +2 -4
- data/spec/delayed/work_queue/parent_process/client_spec.rb +2 -4
- data/spec/delayed/work_queue/parent_process/server_spec.rb +2 -1
- data/spec/delayed/work_queue/parent_process_spec.rb +2 -1
- data/spec/delayed/worker/consul_health_check_spec.rb +3 -1
- data/spec/delayed/worker/health_check_spec.rb +2 -0
- data/spec/delayed/worker_spec.rb +29 -0
- data/spec/gemfiles/51.gemfile.lock +7 -7
- data/spec/gemfiles/52.gemfile.lock +17 -15
- data/spec/gemfiles/60.gemfile.lock +93 -89
- data/spec/migrate/20140924140513_add_story_table.rb +2 -0
- data/spec/redis_job_spec.rb +10 -12
- data/spec/sample_jobs.rb +2 -0
- data/spec/shared/delayed_batch.rb +17 -15
- data/spec/shared/delayed_method.rb +49 -204
- data/spec/shared/performable_method.rb +11 -9
- data/spec/shared/shared_backend.rb +27 -25
- data/spec/shared/testing.rb +7 -5
- data/spec/shared/worker.rb +15 -13
- data/spec/shared_jobs_specs.rb +2 -0
- data/spec/spec_helper.rb +3 -1
- metadata +26 -7
data/spec/redis_job_spec.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require File.expand_path("../spec_helper", __FILE__)
|
2
4
|
|
3
5
|
describe 'Delayed::Backend::Redis::Job' do
|
@@ -5,10 +7,6 @@ describe 'Delayed::Backend::Redis::Job' do
|
|
5
7
|
Delayed.select_backend(Delayed::Backend::Redis::Job)
|
6
8
|
end
|
7
9
|
|
8
|
-
after :all do
|
9
|
-
Delayed.send(:remove_const, :Job)
|
10
|
-
end
|
11
|
-
|
12
10
|
before do
|
13
11
|
Delayed::Testing.clear_all!
|
14
12
|
end
|
@@ -18,8 +16,8 @@ describe 'Delayed::Backend::Redis::Job' do
|
|
18
16
|
describe "tickle_strand" do
|
19
17
|
it "should continue trying to tickle until the strand is empty" do
|
20
18
|
jobs = []
|
21
|
-
3.times { jobs << "test".
|
22
|
-
job = "test".
|
19
|
+
3.times { jobs << "test".delay(ignore_transaction: true, strand: "s1").to_s }
|
20
|
+
job = "test".delay(strand: "s1", ignore_transaction: true).to_s
|
23
21
|
# manually delete the first jobs, bypassing the strand book-keeping
|
24
22
|
jobs.each { |j| Delayed::Job.redis.del(Delayed::Job::Keys::JOB[j.id]) }
|
25
23
|
Delayed::Job.redis.llen(Delayed::Job::Keys::STRAND['s1']).should == 4
|
@@ -29,8 +27,8 @@ describe 'Delayed::Backend::Redis::Job' do
|
|
29
27
|
|
30
28
|
it "should tickle until it finds an existing job" do
|
31
29
|
jobs = []
|
32
|
-
3.times { jobs << "test".
|
33
|
-
job = "test".
|
30
|
+
3.times { jobs << "test".delay(strand: "s1", ignore_transaction: true).to_s }
|
31
|
+
job = "test".delay(strand: "s1", ignore_transaction: true).to_s
|
34
32
|
# manually delete the first jobs, bypassing the strand book-keeping
|
35
33
|
jobs[0...-1].each { |j| Delayed::Job.redis.del(Delayed::Job::Keys::JOB[j.id]) }
|
36
34
|
Delayed::Job.redis.llen(Delayed::Job::Keys::STRAND['s1']).should == 4
|
@@ -44,8 +42,8 @@ describe 'Delayed::Backend::Redis::Job' do
|
|
44
42
|
|
45
43
|
describe "missing jobs in queues" do
|
46
44
|
before do
|
47
|
-
@job = "test".
|
48
|
-
@job2 = "test".
|
45
|
+
@job = "test".delay(ignore_transaction: true).to_s
|
46
|
+
@job2 = "test".delay(ignore_transaction: true).to_s
|
49
47
|
# manually delete the job from redis
|
50
48
|
Delayed::Job.redis.del(Delayed::Job::Keys::JOB[@job.id])
|
51
49
|
end
|
@@ -63,11 +61,11 @@ describe 'Delayed::Backend::Redis::Job' do
|
|
63
61
|
end
|
64
62
|
end
|
65
63
|
|
66
|
-
describe "
|
64
|
+
describe "delay" do
|
67
65
|
it "should schedule job on transaction commit" do
|
68
66
|
before_count = Delayed::Job.jobs_count(:current)
|
69
67
|
ActiveRecord::Base.transaction do
|
70
|
-
job = "string".
|
68
|
+
job = "string".delay.reverse
|
71
69
|
job.should be_nil
|
72
70
|
Delayed::Job.jobs_count(:current).should == before_count
|
73
71
|
end
|
data/spec/sample_jobs.rb
CHANGED
@@ -1,11 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
shared_examples_for 'Delayed::Batch' do
|
2
4
|
context "batching" do
|
3
5
|
it "should batch up all deferrable delayed methods" do
|
4
6
|
later = 1.hour.from_now
|
5
7
|
Delayed::Batch.serial_batch {
|
6
|
-
"string".
|
7
|
-
"string".
|
8
|
-
"string".
|
8
|
+
"string".delay(ignore_transaction: true).size.should be true
|
9
|
+
"string".delay(run_at: later, ignore_transaction: true).reverse.should be_truthy # won't be batched, it'll get its own job
|
10
|
+
"string".delay(ignore_transaction: true).gsub(/./, "!").should be_truthy
|
9
11
|
}
|
10
12
|
batch_jobs = Delayed::Job.find_available(5)
|
11
13
|
regular_jobs = Delayed::Job.list_jobs(:future, 5)
|
@@ -24,8 +26,8 @@ shared_examples_for 'Delayed::Batch' do
|
|
24
26
|
it "should not let you invoke it directly" do
|
25
27
|
later = 1.hour.from_now
|
26
28
|
Delayed::Batch.serial_batch {
|
27
|
-
"string".
|
28
|
-
"string".
|
29
|
+
"string".delay(ignore_transaction: true).size.should be true
|
30
|
+
"string".delay(ignore_transaction: true).gsub(/./, "!").should be true
|
29
31
|
}
|
30
32
|
Delayed::Job.jobs_count(:current).should == 1
|
31
33
|
job = Delayed::Job.find_available(1).first
|
@@ -34,8 +36,8 @@ shared_examples_for 'Delayed::Batch' do
|
|
34
36
|
|
35
37
|
it "should create valid jobs" do
|
36
38
|
Delayed::Batch.serial_batch {
|
37
|
-
"string".
|
38
|
-
"string".
|
39
|
+
"string".delay(ignore_transaction: true).size.should be true
|
40
|
+
"string".delay(ignore_transaction: true).gsub(/./, "!").should be true
|
39
41
|
}
|
40
42
|
Delayed::Job.jobs_count(:current).should == 1
|
41
43
|
|
@@ -58,16 +60,16 @@ shared_examples_for 'Delayed::Batch' do
|
|
58
60
|
it "should create a different batch for each priority" do
|
59
61
|
later = 1.hour.from_now
|
60
62
|
Delayed::Batch.serial_batch {
|
61
|
-
"string".
|
62
|
-
"string".
|
63
|
+
"string".delay(priority: Delayed::LOW_PRIORITY, ignore_transaction: true).size.should be true
|
64
|
+
"string".delay(ignore_transaction: true).gsub(/./, "!").should be true
|
63
65
|
}
|
64
66
|
Delayed::Job.jobs_count(:current).should == 2
|
65
67
|
end
|
66
68
|
|
67
69
|
it "should use the given priority for all, if specified" do
|
68
70
|
Delayed::Batch.serial_batch(:priority => 11) {
|
69
|
-
"string".
|
70
|
-
"string".
|
71
|
+
"string".delay(priority: 20, ignore_transaction: true).size.should be true
|
72
|
+
"string".delay(priority: 15, ignore_transaction: true).gsub(/./, "!").should be true
|
71
73
|
}
|
72
74
|
Delayed::Job.jobs_count(:current).should == 1
|
73
75
|
Delayed::Job.find_available(1).first.priority.should == 11
|
@@ -75,7 +77,7 @@ shared_examples_for 'Delayed::Batch' do
|
|
75
77
|
|
76
78
|
it "should just create the job, if there's only one in the batch" do
|
77
79
|
Delayed::Batch.serial_batch(:priority => 11) {
|
78
|
-
"string".
|
80
|
+
"string".delay(ignore_transaction: true).size.should be true
|
79
81
|
}
|
80
82
|
Delayed::Job.jobs_count(:current).should == 1
|
81
83
|
Delayed::Job.find_available(1).first.tag.should == "String#size"
|
@@ -84,9 +86,9 @@ shared_examples_for 'Delayed::Batch' do
|
|
84
86
|
|
85
87
|
it "should list a job only once when the same call is made multiple times" do
|
86
88
|
Delayed::Batch.serial_batch(:priority => 11) {
|
87
|
-
"string".
|
88
|
-
"string".
|
89
|
-
"string".
|
89
|
+
"string".delay(ignore_transaction: true).size
|
90
|
+
"string".delay(ignore_transaction: true).gsub(/./, "!")
|
91
|
+
"string".delay(ignore_transaction: true).size
|
90
92
|
}
|
91
93
|
batch_job = Delayed::Job.find_available(1).first
|
92
94
|
jobs = batch_job.payload_object.jobs
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
shared_examples_for 'random ruby objects' do
|
2
4
|
def set_queue(name)
|
3
5
|
old_name = Delayed::Settings.queue
|
@@ -6,42 +8,42 @@ shared_examples_for 'random ruby objects' do
|
|
6
8
|
Delayed::Settings.queue = old_name
|
7
9
|
end
|
8
10
|
|
9
|
-
it "should respond_to :
|
10
|
-
Object.new.respond_to?(:
|
11
|
+
it "should respond_to :delay method" do
|
12
|
+
Object.new.respond_to?(:delay)
|
11
13
|
end
|
12
14
|
|
13
|
-
it "should raise a ArgumentError if
|
14
|
-
lambda { Object.new.
|
15
|
+
it "should raise a ArgumentError if delay is called but the target method doesn't exist" do
|
16
|
+
lambda { Object.new.delay.method_that_deos_not_exist }.should raise_error(NoMethodError)
|
15
17
|
end
|
16
18
|
|
17
|
-
it "should add a new entry to the job table when
|
18
|
-
lambda { Object.new.
|
19
|
+
it "should add a new entry to the job table when delay is called on it" do
|
20
|
+
lambda { Object.new.delay.to_s }.should change { Delayed::Job.jobs_count(:current) }.by(1)
|
19
21
|
end
|
20
22
|
|
21
|
-
it "should add a new entry to the job table when
|
22
|
-
lambda { Object.new.
|
23
|
+
it "should add a new entry to the job table when delay is called on it with a queue" do
|
24
|
+
lambda { Object.new.delay(queue: "testqueue").to_s }.should change { Delayed::Job.jobs_count(:current, "testqueue") }.by(1)
|
23
25
|
end
|
24
26
|
|
25
|
-
it "should add a new entry to the job table when
|
26
|
-
lambda { Object.
|
27
|
+
it "should add a new entry to the job table when delay is called on the class" do
|
28
|
+
lambda { Object.delay.to_s }.should change { Delayed::Job.jobs_count(:current) }.by(1)
|
27
29
|
end
|
28
30
|
|
29
|
-
it "should add a new entry to the job table when
|
30
|
-
lambda { Object.
|
31
|
+
it "should add a new entry to the job table when delay is called on the class with a queue" do
|
32
|
+
lambda { Object.delay(queue: "testqueue").to_s }.should change { Delayed::Job.jobs_count(:current, "testqueue") }.by(1)
|
31
33
|
end
|
32
34
|
|
33
35
|
context "class methods" do
|
34
|
-
context "
|
36
|
+
context "handle_asynchronously" do
|
35
37
|
it "should work with default_async" do
|
36
38
|
klass = Class.new do
|
37
39
|
attr_reader :ran
|
38
40
|
def test_method; @ran = true; end
|
39
|
-
|
41
|
+
handle_asynchronously :test_method
|
40
42
|
end
|
41
43
|
obj = klass.new
|
42
44
|
lambda { obj.test_method }.should change { Delayed::Job.jobs_count(:current) }.by(1)
|
43
45
|
obj.ran.should be_falsey
|
44
|
-
lambda { obj.
|
46
|
+
lambda { obj.test_method(synchronous: true) }.should_not change { Delayed::Job.jobs_count(:current) }
|
45
47
|
obj.ran.should be true
|
46
48
|
end
|
47
49
|
|
@@ -49,7 +51,7 @@ shared_examples_for 'random ruby objects' do
|
|
49
51
|
klass = Class.new do
|
50
52
|
attr_reader :ran
|
51
53
|
def test_method; @ran = true; end
|
52
|
-
|
54
|
+
handle_asynchronously :test_method, singleton: -> (obj) { "foobar:#{obj.object_id}" }
|
53
55
|
end
|
54
56
|
|
55
57
|
obj = klass.new
|
@@ -60,10 +62,10 @@ shared_examples_for 'random ruby objects' do
|
|
60
62
|
klass = Class.new do
|
61
63
|
attr_reader :run
|
62
64
|
def test_method(my_kwarg: nil); @run = my_kwarg; end
|
63
|
-
|
65
|
+
handle_asynchronously :test_method
|
64
66
|
|
65
67
|
def other_test(arg); @foo = arg; end
|
66
|
-
|
68
|
+
handle_asynchronously :other_test
|
67
69
|
end
|
68
70
|
|
69
71
|
obj = klass.new
|
@@ -71,117 +73,74 @@ shared_examples_for 'random ruby objects' do
|
|
71
73
|
expect(obj.run).to eq 'foo'
|
72
74
|
end
|
73
75
|
|
74
|
-
it "should
|
75
|
-
klass = Class.new do
|
76
|
-
attr_accessor :ran
|
77
|
-
def test_method; @ran = true; end
|
78
|
-
add_send_later_methods :test_method, {}, false
|
79
|
-
end
|
80
|
-
obj = klass.new
|
81
|
-
lambda { obj.test_method }.should_not change { Delayed::Job.jobs_count(:current) }
|
82
|
-
obj.ran.should be true
|
83
|
-
obj.ran = false
|
84
|
-
obj.ran.should be false
|
85
|
-
lambda { obj.test_method_without_send_later }.should_not change { Delayed::Job.jobs_count(:current) }
|
86
|
-
obj.ran.should be true
|
87
|
-
end
|
88
|
-
|
89
|
-
it "should send along enqueue args and args default async" do
|
76
|
+
it "should send along enqueue args and args" do
|
90
77
|
klass = Class.new do
|
91
78
|
attr_accessor :ran
|
92
79
|
def test_method(*args); @ran = args; end
|
93
|
-
|
80
|
+
handle_asynchronously(:test_method, enqueue_arg_1: :thing)
|
94
81
|
end
|
95
82
|
obj = klass.new
|
96
83
|
method = double()
|
97
84
|
|
98
|
-
expect(Delayed::PerformableMethod).to receive(:new).with(obj, :test_method, [1,2,3, {synchronous: true}
|
85
|
+
expect(Delayed::PerformableMethod).to receive(:new).with(obj, :test_method, args: [1,2,3], kwargs: {synchronous: true}, on_failure: nil, on_permanent_failure: nil).and_return(method)
|
99
86
|
expect(Delayed::Job).to receive(:enqueue).with(method, :enqueue_arg_1 => :thing)
|
100
87
|
obj.test_method(1,2,3)
|
101
88
|
|
102
|
-
expect(Delayed::PerformableMethod).to receive(:new).with(obj, :test_method, [4, {:synchronous=>true}
|
89
|
+
expect(Delayed::PerformableMethod).to receive(:new).with(obj, :test_method, args: [4], kwargs: {:synchronous=>true}, on_failure: nil, on_permanent_failure: nil).and_return(method)
|
103
90
|
expect(Delayed::Job).to receive(:enqueue).with(method, :enqueue_arg_1 => :thing)
|
104
91
|
obj.test_method(4)
|
105
92
|
|
106
93
|
obj.ran.should be_nil
|
107
|
-
obj.
|
94
|
+
obj.test_method(7, synchronous: true)
|
108
95
|
obj.ran.should == [7]
|
109
96
|
obj.ran = nil
|
110
97
|
obj.ran.should == nil
|
111
|
-
obj.
|
98
|
+
obj.test_method(8,9, synchronous: true)
|
112
99
|
obj.ran.should == [8,9]
|
113
100
|
end
|
114
101
|
|
115
|
-
it "should handle punctuation correctly
|
102
|
+
it "should handle punctuation correctly" do
|
116
103
|
klass = Class.new do
|
117
104
|
attr_reader :ran
|
118
105
|
def test_method?; @ran = true; end
|
119
|
-
|
106
|
+
handle_asynchronously :test_method?
|
120
107
|
end
|
121
108
|
obj = klass.new
|
122
109
|
lambda { obj.test_method? }.should change { Delayed::Job.jobs_count(:current) }.by(1)
|
123
110
|
obj.ran.should be_falsey
|
124
|
-
lambda { obj.
|
125
|
-
obj.ran.should be true
|
126
|
-
end
|
127
|
-
|
128
|
-
it "should handle punctuation correctly without default_async" do
|
129
|
-
klass = Class.new do
|
130
|
-
attr_accessor :ran
|
131
|
-
def test_method?; @ran = true; end
|
132
|
-
add_send_later_methods :test_method?, {}, false
|
133
|
-
end
|
134
|
-
obj = klass.new
|
135
|
-
lambda { obj.test_method? }.should_not change { Delayed::Job.jobs_count(:current) }
|
136
|
-
obj.ran.should be true
|
137
|
-
obj.ran = false
|
138
|
-
obj.ran.should be false
|
139
|
-
lambda { obj.test_method_without_send_later? }.should_not change { Delayed::Job.jobs_count(:current) }
|
111
|
+
lambda { obj.test_method?(synchronous: true) }.should_not change { Delayed::Job.jobs_count(:current) }
|
140
112
|
obj.ran.should be true
|
141
113
|
end
|
142
114
|
|
143
|
-
it "should handle assignment punctuation correctly
|
115
|
+
it "should handle assignment punctuation correctly" do
|
144
116
|
klass = Class.new do
|
145
117
|
attr_reader :ran
|
146
118
|
def test_method=(val); @ran = val; end
|
147
|
-
|
119
|
+
handle_asynchronously :test_method=
|
148
120
|
end
|
149
121
|
obj = klass.new
|
150
122
|
lambda { obj.test_method = 3 }.should change { Delayed::Job.jobs_count(:current) }.by(1)
|
151
123
|
obj.ran.should be_nil
|
152
|
-
lambda { obj.
|
124
|
+
lambda { obj.send(:test_method=, 5, synchronous: true) }.should_not change { Delayed::Job.jobs_count(:current) }
|
153
125
|
obj.ran.should == 5
|
154
126
|
end
|
155
127
|
|
156
|
-
it "should
|
157
|
-
klass = Class.new do
|
158
|
-
attr_accessor :ran
|
159
|
-
def test_method=(val); @ran = val; end
|
160
|
-
add_send_later_methods :test_method=, {}, false
|
161
|
-
end
|
162
|
-
obj = klass.new
|
163
|
-
lambda { obj.test_method = 2 }.should_not change { Delayed::Job.jobs_count(:current) }
|
164
|
-
obj.ran.should == 2
|
165
|
-
lambda { obj.test_method_without_send_later = 3 }.should_not change { Delayed::Job.jobs_count(:current) }
|
166
|
-
obj.ran.should == 3
|
167
|
-
end
|
168
|
-
|
169
|
-
it "should correctly sort out method accessibility with default async" do
|
128
|
+
it "should correctly sort out method accessibility" do
|
170
129
|
klass1 = Class.new do
|
171
130
|
def test_method; end
|
172
|
-
|
131
|
+
handle_asynchronously :test_method
|
173
132
|
end
|
174
133
|
|
175
134
|
klass2 = Class.new do
|
176
135
|
protected
|
177
136
|
def test_method; end
|
178
|
-
|
137
|
+
handle_asynchronously :test_method
|
179
138
|
end
|
180
139
|
|
181
140
|
klass3 = Class.new do
|
182
141
|
private
|
183
142
|
def test_method; end
|
184
|
-
|
143
|
+
handle_asynchronously :test_method
|
185
144
|
end
|
186
145
|
|
187
146
|
klass1.public_method_defined?(:test_method).should be true
|
@@ -189,77 +148,6 @@ shared_examples_for 'random ruby objects' do
|
|
189
148
|
klass3.private_method_defined?(:test_method).should be true
|
190
149
|
end
|
191
150
|
end
|
192
|
-
|
193
|
-
context "handle_asynchonously_if_production" do
|
194
|
-
it "should work in production" do
|
195
|
-
expect(Rails.env).to receive(:production?).and_return(true)
|
196
|
-
class TestObject; end
|
197
|
-
expect(TestObject).to receive(:add_send_later_methods).with(:test_method, {}, true)
|
198
|
-
class TestObject
|
199
|
-
def test_method; end
|
200
|
-
handle_asynchronously_if_production :test_method
|
201
|
-
end
|
202
|
-
end
|
203
|
-
|
204
|
-
it "should work in other environments" do
|
205
|
-
class TestObject; end
|
206
|
-
expect(TestObject).to receive(:add_send_later_methods).with(:test_method, {}, false)
|
207
|
-
class TestObject
|
208
|
-
def test_method; end
|
209
|
-
handle_asynchronously_if_production :test_method
|
210
|
-
end
|
211
|
-
end
|
212
|
-
|
213
|
-
it "should pass along enqueue args in production" do
|
214
|
-
expect(Rails.env).to receive(:production?).and_return(true)
|
215
|
-
class TestObject; end
|
216
|
-
expect(TestObject).to receive(:add_send_later_methods).with(:test_method, {:enqueue_arg_1 => true}, true)
|
217
|
-
class TestObject
|
218
|
-
def test_method; end
|
219
|
-
handle_asynchronously_if_production :test_method, :enqueue_arg_1 => true
|
220
|
-
end
|
221
|
-
end
|
222
|
-
|
223
|
-
it "should pass along enqueue args in other environments" do
|
224
|
-
class TestObject; end
|
225
|
-
expect(TestObject).to receive(:add_send_later_methods).with(:test_method, {:enqueue_arg_2 => "thing", :enqueue_arg_3 => 4}, false)
|
226
|
-
class TestObject
|
227
|
-
def test_method; end
|
228
|
-
handle_asynchronously_if_production :test_method, :enqueue_arg_2 => "thing", :enqueue_arg_3 => 4
|
229
|
-
end
|
230
|
-
end
|
231
|
-
end
|
232
|
-
|
233
|
-
context "handle_asynchronously" do
|
234
|
-
it "should work without enqueue_args" do
|
235
|
-
class TestObject; end
|
236
|
-
expect(TestObject).to receive(:add_send_later_methods).with(:test_method, {}, true)
|
237
|
-
class TestObject
|
238
|
-
def test_method; end
|
239
|
-
handle_asynchronously :test_method
|
240
|
-
end
|
241
|
-
end
|
242
|
-
|
243
|
-
it "should work with enqueue_args" do
|
244
|
-
class TestObject; end
|
245
|
-
expect(TestObject).to receive(:add_send_later_methods).with(:test_method, {:enqueue_arg_1 => :thing}, true)
|
246
|
-
class TestObject
|
247
|
-
def test_method; end
|
248
|
-
handle_asynchronously :test_method, :enqueue_arg_1 => :thing
|
249
|
-
end
|
250
|
-
end
|
251
|
-
end
|
252
|
-
|
253
|
-
context "handle_asynchronously_with_queue" do
|
254
|
-
it "should pass along the queue" do
|
255
|
-
class TestObject; end
|
256
|
-
expect(TestObject).to receive(:add_send_later_methods).with(:test_method, {:queue => "myqueue"}, true)
|
257
|
-
class TestObject
|
258
|
-
def test_method; end
|
259
|
-
handle_asynchronously_with_queue :test_method, "myqueue"
|
260
|
-
end
|
261
|
-
end
|
262
|
-
end
|
263
151
|
end
|
264
152
|
|
265
153
|
it "should call send later on methods which are wrapped with handle_asynchronously" do
|
@@ -270,30 +158,19 @@ shared_examples_for 'random ruby objects' do
|
|
270
158
|
job = Delayed::Job.list_jobs(:current, 1).first
|
271
159
|
job.payload_object.class.should == Delayed::PerformableMethod
|
272
160
|
job.payload_object.method.should == :whatever
|
273
|
-
job.payload_object.args.should == [1, 5
|
274
|
-
job.payload_object.
|
275
|
-
end
|
276
|
-
|
277
|
-
it "should call send later on methods which are wrapped with handle_asynchronously_with_queue" do
|
278
|
-
story = Story.create :text => 'Once upon...'
|
279
|
-
|
280
|
-
expect { story.whatever_else(1, 5) }.to change { Delayed::Job.jobs_count(:current, "testqueue") }.by(1)
|
281
|
-
|
282
|
-
job = Delayed::Job.list_jobs(:current, 1, 0, "testqueue").first
|
283
|
-
job.payload_object.class.should == Delayed::PerformableMethod
|
284
|
-
job.payload_object.method.should == :whatever_else
|
285
|
-
job.payload_object.args.should == [1, 5, {:synchronous=>true}]
|
161
|
+
job.payload_object.args.should == [1, 5]
|
162
|
+
job.payload_object.kwargs.should == {:synchronous=>true}
|
286
163
|
job.payload_object.perform.should == 'Once upon...'
|
287
164
|
end
|
288
165
|
|
289
|
-
context "
|
166
|
+
context "delay" do
|
290
167
|
it "should use the default queue if there is one" do
|
291
168
|
set_queue("testqueue") do
|
292
|
-
"string".
|
169
|
+
"string".delay.reverse
|
293
170
|
job = Delayed::Job.list_jobs(:current, 1).first
|
294
171
|
job.queue.should == "testqueue"
|
295
172
|
|
296
|
-
"string".
|
173
|
+
"string".delay(queue: nil).reverse
|
297
174
|
job2 = Delayed::Job.list_jobs(:current, 2).last
|
298
175
|
job2.queue.should == "testqueue"
|
299
176
|
end
|
@@ -304,22 +181,22 @@ shared_examples_for 'random ruby objects' do
|
|
304
181
|
end
|
305
182
|
end
|
306
183
|
|
307
|
-
context "
|
184
|
+
context "delay with run_at" do
|
308
185
|
it "should queue a new job" do
|
309
186
|
lambda do
|
310
|
-
"string".
|
187
|
+
"string".delay(run_at: 1.hour.from_now).length
|
311
188
|
end.should change { Delayed::Job.jobs_count(:future) }.by(1)
|
312
189
|
end
|
313
190
|
|
314
191
|
it "should schedule the job in the future" do
|
315
192
|
time = 1.hour.from_now
|
316
|
-
"string".
|
193
|
+
"string".delay(run_at: time).length
|
317
194
|
job = Delayed::Job.list_jobs(:future, 1).first
|
318
195
|
job.run_at.to_i.should == time.to_i
|
319
196
|
end
|
320
197
|
|
321
198
|
it "should store payload as PerformableMethod" do
|
322
|
-
"string".
|
199
|
+
"string".delay(run_at: 1.hour.from_now).count('r')
|
323
200
|
job = Delayed::Job.list_jobs(:future, 1).first
|
324
201
|
job.payload_object.class.should == Delayed::PerformableMethod
|
325
202
|
job.payload_object.method.should == :count
|
@@ -329,46 +206,14 @@ shared_examples_for 'random ruby objects' do
|
|
329
206
|
|
330
207
|
it "should use the default queue if there is one" do
|
331
208
|
set_queue("testqueue") do
|
332
|
-
"string".
|
209
|
+
"string".delay(run_at: 1.hour.from_now).reverse
|
333
210
|
job = Delayed::Job.list_jobs(:current, 1).first
|
334
211
|
job.queue.should == "testqueue"
|
335
212
|
end
|
336
213
|
end
|
337
214
|
end
|
338
215
|
|
339
|
-
|
340
|
-
it "should queue a new job" do
|
341
|
-
lambda do
|
342
|
-
"string".send_at_with_queue(1.hour.from_now, :length, "testqueue")
|
343
|
-
end.should change { Delayed::Job.jobs_count(:future, "testqueue") }.by(1)
|
344
|
-
end
|
345
|
-
|
346
|
-
it "should schedule the job in the future" do
|
347
|
-
time = 1.hour.from_now
|
348
|
-
"string".send_at_with_queue(time, :length, "testqueue")
|
349
|
-
job = Delayed::Job.list_jobs(:future, 1, 0, "testqueue").first
|
350
|
-
job.run_at.to_i.should == time.to_i
|
351
|
-
end
|
352
|
-
|
353
|
-
it "should override the default queue" do
|
354
|
-
set_queue("default_queue") do
|
355
|
-
"string".send_at_with_queue(1.hour.from_now, :length, "testqueue")
|
356
|
-
job = Delayed::Job.list_jobs(:future, 1, 0, "testqueue").first
|
357
|
-
job.queue.should == "testqueue"
|
358
|
-
end
|
359
|
-
end
|
360
|
-
|
361
|
-
it "should store payload as PerformableMethod" do
|
362
|
-
"string".send_at_with_queue(1.hour.from_now, :count, "testqueue", 'r')
|
363
|
-
job = Delayed::Job.list_jobs(:future, 1, 0, "testqueue").first
|
364
|
-
job.payload_object.class.should == Delayed::PerformableMethod
|
365
|
-
job.payload_object.method.should == :count
|
366
|
-
job.payload_object.args.should == ['r']
|
367
|
-
job.payload_object.perform.should == 1
|
368
|
-
end
|
369
|
-
end
|
370
|
-
|
371
|
-
describe "send_later_unless_in_job" do
|
216
|
+
describe "delay with synchronous argument" do
|
372
217
|
module UnlessInJob
|
373
218
|
@runs = 0
|
374
219
|
def self.runs; @runs; end
|
@@ -378,7 +223,7 @@ shared_examples_for 'random ruby objects' do
|
|
378
223
|
end
|
379
224
|
|
380
225
|
def self.run_later
|
381
|
-
self.
|
226
|
+
self.delay(synchronous: Delayed::Job.in_delayed_job?).run
|
382
227
|
end
|
383
228
|
end
|
384
229
|
|
@@ -387,7 +232,7 @@ shared_examples_for 'random ruby objects' do
|
|
387
232
|
end
|
388
233
|
|
389
234
|
it "should perform immediately if in job" do
|
390
|
-
UnlessInJob.
|
235
|
+
UnlessInJob.delay.run_later
|
391
236
|
job = Delayed::Job.list_jobs(:current, 1).first
|
392
237
|
job.invoke_job
|
393
238
|
UnlessInJob.runs.should == 1
|