inst-jobs 2.3.3 → 2.4.11
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 +9 -7
- data/db/migrate/20110531144916_cleanup_delayed_jobs_indexes.rb +8 -13
- data/db/migrate/20110610213249_optimize_delayed_jobs.rb +8 -8
- data/db/migrate/20110831210257_add_delayed_jobs_next_in_strand.rb +25 -25
- data/db/migrate/20120510004759_delayed_jobs_delete_trigger_lock_for_update.rb +4 -8
- data/db/migrate/20120531150712_drop_psql_jobs_pop_fn.rb +1 -3
- data/db/migrate/20120607164022_delayed_jobs_use_advisory_locks.rb +11 -15
- data/db/migrate/20120607181141_index_jobs_on_locked_by.rb +1 -1
- data/db/migrate/20120608191051_add_jobs_run_at_index.rb +2 -2
- data/db/migrate/20120927184213_change_delayed_jobs_handler_to_text.rb +1 -1
- data/db/migrate/20140505215510_copy_failed_jobs_original_id.rb +2 -3
- data/db/migrate/20150807133223_add_max_concurrent_to_jobs.rb +9 -13
- data/db/migrate/20151210162949_improve_max_concurrent.rb +4 -8
- data/db/migrate/20161206323555_add_back_default_string_limits_jobs.rb +3 -2
- data/db/migrate/20181217155351_speed_up_max_concurrent_triggers.rb +13 -17
- data/db/migrate/20200330230722_add_id_to_get_delayed_jobs_index.rb +8 -8
- data/db/migrate/20200824222232_speed_up_max_concurrent_delete_trigger.rb +72 -77
- data/db/migrate/20200825011002_add_strand_order_override.rb +93 -97
- data/db/migrate/20210809145804_add_n_strand_index.rb +3 -3
- data/db/migrate/20210812210128_add_singleton_column.rb +200 -0
- data/db/migrate/20210917232626_add_delete_conflicting_singletons_before_unlock_trigger.rb +27 -0
- data/db/migrate/20210928174754_fix_singleton_condition_in_before_insert.rb +56 -0
- data/exe/inst_jobs +3 -2
- data/lib/delayed/backend/active_record.rb +204 -150
- data/lib/delayed/backend/base.rb +106 -82
- data/lib/delayed/batch.rb +11 -9
- data/lib/delayed/cli.rb +98 -84
- data/lib/delayed/core_ext/kernel.rb +4 -2
- data/lib/delayed/daemon.rb +70 -74
- data/lib/delayed/job_tracking.rb +26 -25
- data/lib/delayed/lifecycle.rb +27 -24
- data/lib/delayed/log_tailer.rb +17 -17
- data/lib/delayed/logging.rb +13 -16
- data/lib/delayed/message_sending.rb +43 -52
- data/lib/delayed/performable_method.rb +6 -8
- data/lib/delayed/periodic.rb +72 -65
- data/lib/delayed/plugin.rb +2 -4
- data/lib/delayed/pool.rb +198 -193
- data/lib/delayed/server/helpers.rb +6 -6
- data/lib/delayed/server.rb +51 -54
- data/lib/delayed/settings.rb +93 -81
- data/lib/delayed/testing.rb +21 -22
- data/lib/delayed/version.rb +1 -1
- data/lib/delayed/work_queue/in_process.rb +21 -18
- data/lib/delayed/work_queue/parent_process/client.rb +54 -55
- data/lib/delayed/work_queue/parent_process/server.rb +219 -208
- data/lib/delayed/work_queue/parent_process.rb +52 -53
- data/lib/delayed/worker/consul_health_check.rb +21 -19
- data/lib/delayed/worker/health_check.rb +29 -22
- data/lib/delayed/worker/null_health_check.rb +3 -1
- data/lib/delayed/worker/process_helper.rb +8 -9
- data/lib/delayed/worker.rb +271 -265
- data/lib/delayed/yaml_extensions.rb +12 -10
- data/lib/delayed_job.rb +37 -38
- data/lib/inst-jobs.rb +1 -1
- data/spec/active_record_job_spec.rb +129 -136
- data/spec/delayed/cli_spec.rb +7 -7
- data/spec/delayed/daemon_spec.rb +10 -9
- data/spec/delayed/message_sending_spec.rb +16 -9
- data/spec/delayed/periodic_spec.rb +13 -12
- data/spec/delayed/server_spec.rb +38 -38
- data/spec/delayed/settings_spec.rb +26 -25
- data/spec/delayed/work_queue/in_process_spec.rb +7 -8
- data/spec/delayed/work_queue/parent_process/client_spec.rb +17 -12
- data/spec/delayed/work_queue/parent_process/server_spec.rb +70 -41
- data/spec/delayed/work_queue/parent_process_spec.rb +21 -23
- data/spec/delayed/worker/consul_health_check_spec.rb +22 -22
- data/spec/delayed/worker/health_check_spec.rb +60 -52
- data/spec/delayed/worker_spec.rb +28 -25
- data/spec/sample_jobs.rb +45 -15
- data/spec/shared/delayed_batch.rb +74 -67
- data/spec/shared/delayed_method.rb +143 -102
- data/spec/shared/performable_method.rb +39 -38
- data/spec/shared/shared_backend.rb +547 -441
- data/spec/shared/testing.rb +14 -14
- data/spec/shared/worker.rb +155 -147
- data/spec/shared_jobs_specs.rb +13 -13
- data/spec/spec_helper.rb +46 -41
- metadata +79 -55
- data/lib/delayed/backend/redis/bulk_update.lua +0 -50
- data/lib/delayed/backend/redis/destroy_job.lua +0 -2
- data/lib/delayed/backend/redis/enqueue.lua +0 -29
- data/lib/delayed/backend/redis/fail_job.lua +0 -5
- data/lib/delayed/backend/redis/find_available.lua +0 -3
- data/lib/delayed/backend/redis/functions.rb +0 -59
- data/lib/delayed/backend/redis/get_and_lock_next_available.lua +0 -17
- data/lib/delayed/backend/redis/includes/jobs_common.lua +0 -203
- data/lib/delayed/backend/redis/job.rb +0 -528
- data/lib/delayed/backend/redis/set_running.lua +0 -5
- data/lib/delayed/backend/redis/tickle_strand.lua +0 -2
- data/spec/gemfiles/52.gemfile +0 -7
- data/spec/gemfiles/60.gemfile +0 -7
- data/spec/gemfiles/60.gemfile.lock +0 -246
- data/spec/gemfiles/61.gemfile +0 -7
- data/spec/redis_job_spec.rb +0 -148
@@ -1,30 +1,31 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "spec_helper"
|
4
4
|
|
5
5
|
RSpec.describe Delayed::Periodic do
|
6
|
-
around
|
6
|
+
around do |block|
|
7
7
|
# make sure we can use ".cron" and
|
8
8
|
# such safely without leaking global state
|
9
|
-
prev_sched =
|
10
|
-
prev_ovr =
|
11
|
-
|
12
|
-
|
9
|
+
prev_sched = described_class.scheduled
|
10
|
+
prev_ovr = described_class.overrides
|
11
|
+
described_class.scheduled = {}
|
12
|
+
described_class.overrides = {}
|
13
13
|
block.call
|
14
14
|
ensure
|
15
|
-
|
16
|
-
|
15
|
+
described_class.scheduled = prev_sched
|
16
|
+
described_class.overrides = prev_ovr
|
17
17
|
Delayed::Job.delete_all
|
18
18
|
end
|
19
19
|
|
20
20
|
describe ".cron" do
|
21
|
-
let(:job_name){
|
21
|
+
let(:job_name) { "just a test" }
|
22
|
+
|
22
23
|
it "provides a tag by default for periodic jobs" do
|
23
|
-
|
24
|
+
described_class.cron job_name, "*/10 * * * *" do
|
24
25
|
# no-op
|
25
26
|
end
|
26
|
-
instance =
|
27
|
-
expect(instance).
|
27
|
+
instance = described_class.scheduled[job_name]
|
28
|
+
expect(instance).not_to be_nil
|
28
29
|
expect(instance.enqueue_args[:singleton]).to eq("periodic: just a test")
|
29
30
|
end
|
30
31
|
end
|
data/spec/delayed/server_spec.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require "spec_helper"
|
4
|
+
require "delayed/server"
|
5
5
|
|
6
6
|
RSpec.describe Delayed::Server, sinatra: true do
|
7
7
|
include Rack::Test::Methods
|
@@ -24,78 +24,78 @@ RSpec.describe Delayed::Server, sinatra: true do
|
|
24
24
|
before do
|
25
25
|
3.times do |i|
|
26
26
|
Delayed::Job.create!({
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
27
|
+
run_at: Time.zone.now,
|
28
|
+
locked_at: Time.zone.now,
|
29
|
+
locked_by: "dummy-runner-#{i}:${$$}"
|
30
|
+
})
|
31
31
|
end
|
32
|
-
get
|
32
|
+
get "/running"
|
33
33
|
end
|
34
34
|
|
35
|
-
it
|
35
|
+
it "must return a json object with the running job data in an array", aggregate_failures: true do
|
36
36
|
expect(last_response).to be_ok
|
37
|
-
expect(parsed_body[
|
38
|
-
expect(parsed_body[
|
37
|
+
expect(parsed_body["data"]).to be_an Array
|
38
|
+
expect(parsed_body["data"].size).to eq 3
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
42
42
|
describe "get '/jobs'" do
|
43
|
-
let!(:
|
44
|
-
let!(:
|
45
|
-
let!(:
|
43
|
+
let!(:job1) { Delayed::Job.enqueue(SimpleJob.new, strand: "strand-1") }
|
44
|
+
let!(:job2) { Delayed::Job.enqueue(SimpleJob.new, strand: "strand-2") }
|
45
|
+
let!(:job3) { Delayed::Job.enqueue(SimpleJob.new, strand: "strand-3") }
|
46
46
|
|
47
|
-
context
|
47
|
+
context "with the flavor param set to id" do
|
48
48
|
before do
|
49
|
-
get "/jobs?flavor=id&search_term=#{
|
49
|
+
get "/jobs?flavor=id&search_term=#{job2.id}"
|
50
50
|
end
|
51
51
|
|
52
|
-
it
|
53
|
-
jobs = parsed_body[
|
54
|
-
job_ids = jobs.map{ |j| j[
|
55
|
-
expect(job_ids).to eq [
|
52
|
+
it "must only return the job with the id specified in the search_term param" do
|
53
|
+
jobs = parsed_body["data"]
|
54
|
+
job_ids = jobs.map { |j| j["id"] }
|
55
|
+
expect(job_ids).to eq [job2.id]
|
56
56
|
end
|
57
57
|
|
58
|
-
it
|
59
|
-
expect(parsed_body[
|
58
|
+
it "must set recordsFiltered in the response to 1" do
|
59
|
+
expect(parsed_body["recordsFiltered"]).to eq 1
|
60
60
|
end
|
61
61
|
end
|
62
62
|
end
|
63
63
|
|
64
64
|
describe "post '/bulk_update'" do
|
65
|
-
let!(:
|
66
|
-
let!(:
|
67
|
-
let!(:
|
65
|
+
let!(:job1) { Delayed::Job.enqueue(SimpleJob.new, strand: "strand-1") }
|
66
|
+
let!(:job2) { Delayed::Job.enqueue(SimpleJob.new, strand: "strand-2") }
|
67
|
+
let!(:job3) { Delayed::Job.enqueue(SimpleJob.new, strand: "strand-3") }
|
68
68
|
|
69
|
-
context
|
69
|
+
context "with update enabled" do
|
70
70
|
before do
|
71
71
|
@update = true
|
72
|
-
post "/bulk_update",
|
72
|
+
post "/bulk_update", JSON.generate(action: "destroy", ids: [job1.id])
|
73
73
|
end
|
74
74
|
|
75
|
-
it
|
76
|
-
expect{ Delayed::Job.find(
|
77
|
-
expect(Delayed::Job.find(
|
78
|
-
expect(Delayed::Job.find(
|
75
|
+
it "must remove job1" do
|
76
|
+
expect { Delayed::Job.find(job1.id) }.to raise_error(ActiveRecord::RecordNotFound)
|
77
|
+
expect(Delayed::Job.find(job2.id)).not_to be_nil
|
78
|
+
expect(Delayed::Job.find(job3.id)).not_to be_nil
|
79
79
|
end
|
80
80
|
|
81
|
-
it
|
81
|
+
it "must return ok" do
|
82
82
|
expect(last_response.ok?).to be true
|
83
83
|
end
|
84
84
|
end
|
85
85
|
|
86
|
-
context
|
86
|
+
context "with update disabled" do
|
87
87
|
before do
|
88
88
|
@update = false
|
89
|
-
post "/bulk_update",
|
89
|
+
post "/bulk_update", JSON.generate(action: "destroy", ids: [job1.id])
|
90
90
|
end
|
91
91
|
|
92
|
-
it
|
93
|
-
expect(Delayed::Job.find(
|
94
|
-
expect(Delayed::Job.find(
|
95
|
-
expect(Delayed::Job.find(
|
92
|
+
it "must not remove job1" do
|
93
|
+
expect(Delayed::Job.find(job1.id)).not_to be_nil
|
94
|
+
expect(Delayed::Job.find(job2.id)).not_to be_nil
|
95
|
+
expect(Delayed::Job.find(job3.id)).not_to be_nil
|
96
96
|
end
|
97
97
|
|
98
|
-
it
|
98
|
+
it "must return forbidden" do
|
99
99
|
expect(last_response.forbidden?).to be true
|
100
100
|
end
|
101
101
|
end
|
@@ -1,47 +1,48 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "spec_helper"
|
4
4
|
|
5
5
|
RSpec.describe Delayed::Settings do
|
6
|
-
let(:configfile)
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
6
|
+
let(:configfile) do
|
7
|
+
<<~YAML
|
8
|
+
default:
|
9
|
+
workers:
|
10
|
+
- queue: myqueue
|
11
|
+
workers: 2
|
12
|
+
- queue: secondqueue
|
13
|
+
max_priority: 7
|
14
|
+
max_attempts: 1
|
14
15
|
YAML
|
15
|
-
|
16
|
+
end
|
16
17
|
|
17
|
-
describe
|
18
|
-
it
|
18
|
+
describe ".worker_config" do
|
19
|
+
it "merges each worker config with the top-level config" do
|
19
20
|
expect(File).to receive(:read).with("fname").and_return(configfile)
|
20
21
|
config = described_class.worker_config("fname")
|
21
22
|
expect(config[:workers]).to eq([
|
22
|
-
|
23
|
-
|
24
|
-
|
23
|
+
{ "queue" => "myqueue", "workers" => 2, "max_attempts" => 1 },
|
24
|
+
{ "queue" => "secondqueue", "max_priority" => 7, "max_attempts" => 1 }
|
25
|
+
])
|
25
26
|
end
|
26
27
|
end
|
27
28
|
|
28
|
-
describe
|
29
|
-
it
|
29
|
+
describe ".apply_worker_config!" do
|
30
|
+
it "applies global settings from the given config" do
|
30
31
|
expect(described_class).to receive(:last_ditch_logfile=).with(true)
|
31
|
-
described_class.apply_worker_config!(
|
32
|
+
described_class.apply_worker_config!("last_ditch_logfile" => true)
|
32
33
|
end
|
33
34
|
|
34
|
-
it
|
35
|
-
described_class.apply_worker_config!(
|
35
|
+
it "merges in parent_process overrides to default config" do
|
36
|
+
described_class.apply_worker_config!("parent_process" => { "foo" => "bar" })
|
36
37
|
|
37
|
-
expect(
|
38
|
+
expect(described_class.parent_process).to include("foo" => "bar")
|
38
39
|
end
|
39
40
|
end
|
40
41
|
|
41
|
-
describe
|
42
|
-
it
|
43
|
-
|
44
|
-
expect(
|
42
|
+
describe ".parent_process_client_timeout=" do
|
43
|
+
it "must update the value in the parent_process settings hash" do
|
44
|
+
described_class.parent_process_client_timeout = 42
|
45
|
+
expect(described_class.parent_process["server_socket_timeout"]).to eq 42
|
45
46
|
end
|
46
47
|
end
|
47
48
|
end
|
@@ -1,27 +1,26 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "spec_helper"
|
4
4
|
|
5
5
|
RSpec.describe Delayed::WorkQueue::InProcess do
|
6
6
|
before :all do
|
7
7
|
Delayed.select_backend(Delayed::Backend::ActiveRecord::Job)
|
8
8
|
end
|
9
9
|
|
10
|
-
after
|
10
|
+
after do
|
11
11
|
Delayed::Worker.lifecycle.reset!
|
12
12
|
end
|
13
13
|
|
14
|
-
let(:
|
15
|
-
let(:worker_config) { {queue: "test", min_priority: 1, max_priority: 2} }
|
14
|
+
let(:worker_config) { { queue: "test", min_priority: 1, max_priority: 2 } }
|
16
15
|
let(:args) { ["worker_name", worker_config] }
|
17
16
|
|
18
|
-
it
|
17
|
+
it "triggers the lifecycle event around the pop" do
|
19
18
|
called = false
|
20
19
|
Delayed::Worker.lifecycle.around(:work_queue_pop) do |queue, &cb|
|
21
20
|
expect(queue).to eq(subject)
|
22
|
-
expect(Delayed::Job).to receive(:get_and_lock_next_available)
|
23
|
-
with("worker_name", "test", 1, 2)
|
24
|
-
and_return(:job)
|
21
|
+
expect(Delayed::Job).to receive(:get_and_lock_next_available)
|
22
|
+
.with("worker_name", "test", 1, 2)
|
23
|
+
.and_return(:job)
|
25
24
|
called = true
|
26
25
|
cb.call(queue)
|
27
26
|
end
|
@@ -1,22 +1,23 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "spec_helper"
|
4
4
|
|
5
5
|
RSpec.describe Delayed::WorkQueue::ParentProcess::Client do
|
6
|
-
|
7
|
-
|
8
|
-
let(:
|
6
|
+
subject { described_class.new(addrinfo).tap(&:init) }
|
7
|
+
|
8
|
+
let(:addrinfo) { double("Addrinfo") }
|
9
|
+
let(:connection) { double("Socket") }
|
9
10
|
let(:job) { Delayed::Job.new(locked_by: "worker_name") }
|
10
11
|
let(:worker_config) { { queue: "queue_name", min_priority: 1, max_priority: 2 } }
|
11
12
|
let(:args) { ["worker_name", worker_config] }
|
12
13
|
let(:job_args) { [["worker_name"], "queue_name", 1, 2] }
|
13
14
|
|
14
15
|
before :all do
|
15
|
-
FileUtils.mkdir_p(Delayed::Settings.expand_rails_path(
|
16
|
+
FileUtils.mkdir_p(Delayed::Settings.expand_rails_path("tmp"))
|
16
17
|
Delayed.select_backend(Delayed::Backend::ActiveRecord::Job)
|
17
18
|
end
|
18
19
|
|
19
|
-
it
|
20
|
+
it "marshals the given arguments to the server and returns the response" do
|
20
21
|
expect(addrinfo).to receive(:connect).once.and_return(connection)
|
21
22
|
expect(connection).to receive(:eof?).and_return(false)
|
22
23
|
expect(IO).to receive(:select).and_return([[connection], nil, nil])
|
@@ -26,7 +27,7 @@ RSpec.describe Delayed::WorkQueue::ParentProcess::Client do
|
|
26
27
|
expect(response).to eq(job)
|
27
28
|
end
|
28
29
|
|
29
|
-
it
|
30
|
+
it "returns nil and then reconnects on socket write error" do
|
30
31
|
expect(addrinfo).to receive(:connect).once.and_return(connection)
|
31
32
|
expect(Marshal).to receive(:dump).and_raise(SystemCallError.new("failure"))
|
32
33
|
expect(IO).to receive(:select).and_return([[connection], nil, nil])
|
@@ -42,7 +43,7 @@ RSpec.describe Delayed::WorkQueue::ParentProcess::Client do
|
|
42
43
|
expect(response).to eq(job)
|
43
44
|
end
|
44
45
|
|
45
|
-
it
|
46
|
+
it "returns nil and then reconnects when the socket indicates eof" do
|
46
47
|
expect(addrinfo).to receive(:connect).once.and_return(connection)
|
47
48
|
expect(connection).to receive(:eof?).and_return(true)
|
48
49
|
expect(Marshal).to receive(:dump).with(args, connection).ordered
|
@@ -59,17 +60,19 @@ RSpec.describe Delayed::WorkQueue::ParentProcess::Client do
|
|
59
60
|
expect(response).to eq(job)
|
60
61
|
end
|
61
62
|
|
62
|
-
it
|
63
|
+
it "errors if the response is not a locked job" do
|
63
64
|
expect(addrinfo).to receive(:connect).once.and_return(connection)
|
64
65
|
expect(Marshal).to receive(:dump).with(args, connection)
|
65
66
|
expect(IO).to receive(:select).and_return([[connection], nil, nil])
|
66
67
|
expect(Marshal).to receive(:load).with(connection).and_return(:not_a_job)
|
67
68
|
expect(connection).to receive(:eof?).and_return(false)
|
68
69
|
|
69
|
-
expect
|
70
|
+
expect do
|
71
|
+
subject.get_and_lock_next_available(*args)
|
72
|
+
end.to raise_error(Delayed::WorkQueue::ParentProcess::ProtocolError)
|
70
73
|
end
|
71
74
|
|
72
|
-
it
|
75
|
+
it "errors if the response is a job not locked by this worker" do
|
73
76
|
expect(addrinfo).to receive(:connect).once.and_return(connection)
|
74
77
|
expect(Marshal).to receive(:dump).with(args, connection)
|
75
78
|
job.locked_by = "somebody_else"
|
@@ -77,6 +80,8 @@ RSpec.describe Delayed::WorkQueue::ParentProcess::Client do
|
|
77
80
|
expect(Marshal).to receive(:load).with(connection).and_return(job)
|
78
81
|
expect(connection).to receive(:eof?).and_return(false)
|
79
82
|
|
80
|
-
expect
|
83
|
+
expect do
|
84
|
+
subject.get_and_lock_next_available(*args)
|
85
|
+
end.to raise_error(Delayed::WorkQueue::ParentProcess::ProtocolError)
|
81
86
|
end
|
82
87
|
end
|
@@ -1,32 +1,37 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "spec_helper"
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
attr_reader :id
|
5
|
+
class JobClass
|
6
|
+
attr_reader :id
|
8
7
|
|
9
|
-
|
10
|
-
|
11
|
-
|
8
|
+
def initialize
|
9
|
+
@id = rand
|
10
|
+
end
|
12
11
|
|
13
|
-
|
14
|
-
|
15
|
-
end
|
12
|
+
def ==(other)
|
13
|
+
id == other.id
|
16
14
|
end
|
15
|
+
end
|
16
|
+
|
17
|
+
RSpec.describe Delayed::WorkQueue::ParentProcess::Server do
|
18
|
+
subject { described_class.new(listen_socket) }
|
17
19
|
|
18
20
|
let(:parent) { Delayed::WorkQueue::ParentProcess.new }
|
19
|
-
let(:subject) { described_class.new(listen_socket) }
|
20
21
|
let(:listen_socket) { Socket.unix_server_socket(parent.server_address) }
|
21
22
|
let(:job) { JobClass.new }
|
22
23
|
let(:worker_config) { { queue: "queue_name", min_priority: 1, max_priority: 2 } }
|
23
24
|
let(:args) { ["worker_name", worker_config] }
|
24
25
|
let(:job_args) { [["worker_name"], "queue_name", 1, 2, hash_including(prefetch: 4)] }
|
25
26
|
|
27
|
+
before do
|
28
|
+
Delayed::Worker.lifecycle.reset!
|
29
|
+
end
|
30
|
+
|
26
31
|
before :all do
|
27
32
|
Delayed.select_backend(Delayed::Backend::ActiveRecord::Job)
|
28
33
|
Delayed::Settings.parent_process = {
|
29
|
-
|
34
|
+
"server_address" => "/tmp/inst-jobs-test.sock"
|
30
35
|
}
|
31
36
|
end
|
32
37
|
|
@@ -34,27 +39,28 @@ RSpec.describe Delayed::WorkQueue::ParentProcess::Server do
|
|
34
39
|
Delayed::Settings.parent_process = {}
|
35
40
|
end
|
36
41
|
|
37
|
-
after
|
38
|
-
File.unlink(
|
42
|
+
after do
|
43
|
+
File.unlink("/tmp/inst-jobs-test.sock") if File.exist?("/tmp/inst-jobs-test.sock")
|
44
|
+
Delayed::Worker.lifecycle.reset!
|
39
45
|
end
|
40
46
|
|
41
|
-
it
|
42
|
-
|
47
|
+
it "accepts new clients" do
|
48
|
+
Socket.unix(subject.listen_socket.local_address.unix_path)
|
43
49
|
expect { subject.run_once }.to change(subject, :connected_clients).by(1)
|
44
50
|
end
|
45
51
|
|
46
|
-
it
|
52
|
+
it "queries the queue on client request" do
|
47
53
|
client = Socket.unix(subject.listen_socket.local_address.unix_path)
|
48
54
|
subject.run_once
|
49
55
|
|
50
|
-
expect(Delayed::Job).to receive(:get_and_lock_next_available).with(*job_args).and_return(
|
56
|
+
expect(Delayed::Job).to receive(:get_and_lock_next_available).with(*job_args).and_return("worker_name" => job)
|
51
57
|
Marshal.dump(args, client)
|
52
58
|
subject.run_once
|
53
59
|
expect(client).to be_ready
|
54
60
|
expect(Marshal.load(client)).to eq(job)
|
55
61
|
end
|
56
62
|
|
57
|
-
it
|
63
|
+
it "can pop multiple jobs at once" do
|
58
64
|
client1 = Socket.unix(subject.listen_socket.local_address.unix_path)
|
59
65
|
subject.run_once
|
60
66
|
client2 = Socket.unix(subject.listen_socket.local_address.unix_path)
|
@@ -62,8 +68,8 @@ RSpec.describe Delayed::WorkQueue::ParentProcess::Server do
|
|
62
68
|
|
63
69
|
job1 = JobClass.new
|
64
70
|
job2 = JobClass.new
|
65
|
-
job_args = [[
|
66
|
-
jobs = {
|
71
|
+
job_args = [%w[worker_name1 worker_name2], "queue_name", 1, 2, hash_including(prefetch: 3)]
|
72
|
+
jobs = { "worker_name1" => job1, "worker_name2" => job2 }
|
67
73
|
|
68
74
|
expect(Delayed::Job).to receive(:get_and_lock_next_available).with(*job_args).and_return(jobs)
|
69
75
|
Marshal.dump(["worker_name1", worker_config], client1)
|
@@ -73,27 +79,28 @@ RSpec.describe Delayed::WorkQueue::ParentProcess::Server do
|
|
73
79
|
expect(Marshal.load(client2)).to eq(job2)
|
74
80
|
end
|
75
81
|
|
76
|
-
it
|
82
|
+
it "will prefetch and use jobs" do
|
77
83
|
client = Socket.unix(subject.listen_socket.local_address.unix_path)
|
78
84
|
subject.run_once
|
79
85
|
|
80
|
-
allow(subject).to receive(:prefetch_owner).and_return(
|
81
|
-
job_args = [["worker_name1"], "queue_name", 1, 2,
|
82
|
-
|
83
|
-
job2.
|
84
|
-
|
85
|
-
job3.
|
86
|
-
|
86
|
+
allow(subject).to receive(:prefetch_owner).and_return("work_queue:X")
|
87
|
+
job_args = [["worker_name1"], "queue_name", 1, 2,
|
88
|
+
{ prefetch: 4, prefetch_owner: "work_queue:X", forced_latency: 6.0 }]
|
89
|
+
job2 = Delayed::Job.new(tag: "tag")
|
90
|
+
job2.create_and_lock!("work_queue:X")
|
91
|
+
job3 = Delayed::Job.new(tag: "tag")
|
92
|
+
job3.create_and_lock!("work_queue:X")
|
93
|
+
jobs = { "worker_name1" => job, "work_queue:X" => [job2, job3] }
|
87
94
|
|
88
95
|
expect(Delayed::Job).to receive(:get_and_lock_next_available).once.with(*job_args).and_return(jobs)
|
89
96
|
Marshal.dump(["worker_name1", worker_config], client)
|
90
97
|
subject.run_once
|
91
|
-
expect(subject).
|
98
|
+
expect(subject).not_to be_all_workers_idle
|
92
99
|
expect(Marshal.load(client)).to eq(job)
|
93
100
|
|
94
101
|
Marshal.dump(["worker_name1", worker_config], client)
|
95
102
|
subject.run_once
|
96
|
-
expect(subject).
|
103
|
+
expect(subject).not_to be_all_workers_idle
|
97
104
|
expect(Marshal.load(client)).to eq(job2)
|
98
105
|
end
|
99
106
|
|
@@ -107,7 +114,10 @@ RSpec.describe Delayed::WorkQueue::ParentProcess::Server do
|
|
107
114
|
expect(client).not_to be_ready
|
108
115
|
|
109
116
|
# next time around, return the result
|
110
|
-
expect(Delayed::Job).to receive(:get_and_lock_next_available)
|
117
|
+
expect(Delayed::Job).to receive(:get_and_lock_next_available)
|
118
|
+
.with(*job_args)
|
119
|
+
.and_return("worker_name" => job)
|
120
|
+
.ordered
|
111
121
|
allow(Delayed::Settings).to receive(:sleep_delay).and_return(0)
|
112
122
|
allow(Delayed::Settings).to receive(:sleep_delay_stagger).and_return(0)
|
113
123
|
subject.run_once
|
@@ -115,7 +125,7 @@ RSpec.describe Delayed::WorkQueue::ParentProcess::Server do
|
|
115
125
|
expect(Marshal.load(client)).to eq(job)
|
116
126
|
end
|
117
127
|
|
118
|
-
it
|
128
|
+
it "drops the client on i/o error" do
|
119
129
|
client = Socket.unix(subject.listen_socket.local_address.unix_path)
|
120
130
|
subject.run_once
|
121
131
|
|
@@ -125,7 +135,7 @@ RSpec.describe Delayed::WorkQueue::ParentProcess::Server do
|
|
125
135
|
expect { subject.run_once }.to change(subject, :connected_clients).by(-1)
|
126
136
|
end
|
127
137
|
|
128
|
-
it
|
138
|
+
it "drops the client when the client disconnects" do
|
129
139
|
client = Socket.unix(subject.listen_socket.local_address.unix_path)
|
130
140
|
subject.run_once
|
131
141
|
|
@@ -138,7 +148,7 @@ RSpec.describe Delayed::WorkQueue::ParentProcess::Server do
|
|
138
148
|
expect(subject.instance_variable_get(:@waiting_clients).first.last).to eq []
|
139
149
|
end
|
140
150
|
|
141
|
-
it
|
151
|
+
it "drops the client when a write fails" do
|
142
152
|
client = Socket.unix(subject.listen_socket.local_address.unix_path)
|
143
153
|
subject.run_once
|
144
154
|
|
@@ -151,7 +161,7 @@ RSpec.describe Delayed::WorkQueue::ParentProcess::Server do
|
|
151
161
|
# don't let the server see the close and process it there; we want to check a failure later
|
152
162
|
expect(subject).to receive(:handle_request).with(server_client_socket)
|
153
163
|
|
154
|
-
expect(Delayed::Job).to receive(:get_and_lock_next_available).with(*job_args).and_return(
|
164
|
+
expect(Delayed::Job).to receive(:get_and_lock_next_available).with(*job_args).and_return("worker_name" => job)
|
155
165
|
# the job gets unlocked
|
156
166
|
expect(Delayed::Job).to receive(:unlock).with([job])
|
157
167
|
subject.run_once
|
@@ -161,14 +171,14 @@ RSpec.describe Delayed::WorkQueue::ParentProcess::Server do
|
|
161
171
|
expect(subject.instance_variable_get(:@waiting_clients).first.last).to eq []
|
162
172
|
end
|
163
173
|
|
164
|
-
it
|
174
|
+
it "tracks when clients are idle" do
|
165
175
|
expect(subject.all_workers_idle?).to be(true)
|
166
176
|
|
167
177
|
client = Socket.unix(subject.listen_socket.local_address.unix_path)
|
168
178
|
subject.run_once
|
169
179
|
expect(subject.all_workers_idle?).to be(true)
|
170
180
|
|
171
|
-
expect(Delayed::Job).to receive(:get_and_lock_next_available).with(*job_args).and_return(
|
181
|
+
expect(Delayed::Job).to receive(:get_and_lock_next_available).with(*job_args).and_return("worker_name" => job)
|
172
182
|
Marshal.dump(args, client)
|
173
183
|
subject.run_once
|
174
184
|
expect(subject.all_workers_idle?).to be(false)
|
@@ -179,7 +189,7 @@ RSpec.describe Delayed::WorkQueue::ParentProcess::Server do
|
|
179
189
|
expect(subject.all_workers_idle?).to be(true)
|
180
190
|
end
|
181
191
|
|
182
|
-
it
|
192
|
+
it "triggers the lifecycle event around the pop" do
|
183
193
|
called = false
|
184
194
|
client = Socket.unix(subject.listen_socket.local_address.unix_path)
|
185
195
|
subject.run_once
|
@@ -187,7 +197,7 @@ RSpec.describe Delayed::WorkQueue::ParentProcess::Server do
|
|
187
197
|
Delayed::Worker.lifecycle.around(:work_queue_pop) do |queue, &cb|
|
188
198
|
expect(subject.all_workers_idle?).to be(true)
|
189
199
|
expect(queue).to eq(subject)
|
190
|
-
expect(Delayed::Job).to receive(:get_and_lock_next_available).with(*job_args).and_return(
|
200
|
+
expect(Delayed::Job).to receive(:get_and_lock_next_available).with(*job_args).and_return("worker_name" => job)
|
191
201
|
called = true
|
192
202
|
res = cb.call(queue)
|
193
203
|
expect(subject.all_workers_idle?).to be(false)
|
@@ -200,5 +210,24 @@ RSpec.describe Delayed::WorkQueue::ParentProcess::Server do
|
|
200
210
|
expect(Marshal.load(client)).to eq(job)
|
201
211
|
expect(called).to eq(true)
|
202
212
|
end
|
203
|
-
end
|
204
213
|
|
214
|
+
it "deletes the correct worker when transferring jobs" do
|
215
|
+
client1 = Socket.unix(subject.listen_socket.local_address.unix_path)
|
216
|
+
client2 = Socket.unix(subject.listen_socket.local_address.unix_path)
|
217
|
+
subject.run_once
|
218
|
+
subject.run_once
|
219
|
+
|
220
|
+
Marshal.dump(args, client1)
|
221
|
+
Marshal.dump(["worker_name2", worker_config], client2)
|
222
|
+
subject.run_once
|
223
|
+
subject.run_once
|
224
|
+
|
225
|
+
waiting_clients = subject.instance_variable_get(:@waiting_clients)
|
226
|
+
expect(waiting_clients.first.last.length).to eq 2
|
227
|
+
|
228
|
+
expect(Delayed::Job).to receive(:get_and_lock_next_available).and_return("worker_name" => job,
|
229
|
+
"worker_name2" => job)
|
230
|
+
subject.run_once
|
231
|
+
expect(waiting_clients.first.last).to be_empty
|
232
|
+
end
|
233
|
+
end
|