inst-jobs 0.13.1 → 0.13.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/delayed/settings.rb +0 -2
- data/lib/delayed/version.rb +1 -1
- data/lib/delayed/work_queue/parent_process/client.rb +4 -9
- data/lib/delayed/work_queue/parent_process/server.rb +13 -16
- data/spec/delayed/work_queue/parent_process/client_spec.rb +0 -23
- data/spec/delayed/work_queue/parent_process/server_spec.rb +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9b0d5ed365c051a94b8b26f7fc43b66ddf472221
|
4
|
+
data.tar.gz: 53d13170b1a9f85ea4e9064932e674b6059063ba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d911c43ce7aadb8d1373c96d82829ea2ecfc4ffecb1b8ea1243b713cbcb30aa57b6721fa77eea5446b72bb741db128dbf4ba7da9c4dcf57b6e34fa87261483d7
|
7
|
+
data.tar.gz: 02ba0072c4d9c1335fcf8d70e91368a47e34b9ae2d2748a2749def1f0f0e4d4ce76114ad0baf7da5bdf23e09abab0079466f1430076dec959adb096fd72698c8
|
data/lib/delayed/settings.rb
CHANGED
@@ -33,12 +33,10 @@ module Delayed
|
|
33
33
|
mattr_accessor(*SETTINGS_WITH_ARGS)
|
34
34
|
|
35
35
|
PARENT_PROCESS_DEFAULTS = {
|
36
|
-
server_receive_timeout: 10.0,
|
37
36
|
server_socket_timeout: 10.0,
|
38
37
|
pending_jobs_idle_timeout: 30.0,
|
39
38
|
|
40
39
|
client_connect_timeout: 2.0,
|
41
|
-
client_receive_timeout: 10.0,
|
42
40
|
|
43
41
|
# We'll accept a partial, relative path and assume we want it inside
|
44
42
|
# Rails.root with inst-jobs.sock appended if provided a directory.
|
data/lib/delayed/version.rb
CHANGED
@@ -9,7 +9,6 @@ class ParentProcess
|
|
9
9
|
def initialize(addrinfo, config: Settings.parent_process)
|
10
10
|
@addrinfo = addrinfo
|
11
11
|
@connect_timeout = config['client_connect_timeout'] || 2
|
12
|
-
@receive_timeout = config['client_receive_timeout'] || 10
|
13
12
|
end
|
14
13
|
|
15
14
|
def get_and_lock_next_available(worker_name, worker_config)
|
@@ -19,15 +18,11 @@ class ParentProcess
|
|
19
18
|
# to wait for anything to be available on the 'wire', this is a valid
|
20
19
|
# assumption because we control the server and it's a Unix domain socket,
|
21
20
|
# not TCP.
|
22
|
-
if socket.
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
raise(ProtocolError, "response is not a locked job: #{response.inspect}")
|
27
|
-
end
|
21
|
+
return reset_connection if socket.eof? # Other end closed gracefully, so should we
|
22
|
+
Marshal.load(socket).tap do |response|
|
23
|
+
unless response.nil? || (response.is_a?(Delayed::Job) && response.locked_by == worker_name)
|
24
|
+
raise(ProtocolError, "response is not a locked job: #{response.inspect}")
|
28
25
|
end
|
29
|
-
else
|
30
|
-
reset_connection
|
31
26
|
end
|
32
27
|
rescue SystemCallError, IOError => ex
|
33
28
|
logger.error("Work queue connection lost, reestablishing on next poll. (#{ex})")
|
@@ -15,7 +15,6 @@ class ParentProcess
|
|
15
15
|
|
16
16
|
@config = config
|
17
17
|
@client_timeout = config['server_socket_timeout'] || 10.0 # left for backwards compat
|
18
|
-
@receive_timeout = config['server_receive_timeout'] || 10.0
|
19
18
|
end
|
20
19
|
|
21
20
|
def connected_clients
|
@@ -82,19 +81,13 @@ class ParentProcess
|
|
82
81
|
# There is an assumption here that the client will never send a partial
|
83
82
|
# request and then leave the socket open. Doing so would leave us hanging
|
84
83
|
# in Marshal.load forever. This is only a reasonable assumption because we
|
85
|
-
# control the client.
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
client.working = false
|
93
|
-
(@waiting_clients[worker_config] ||= []) << client
|
94
|
-
else
|
95
|
-
drop_socket(socket)
|
96
|
-
end
|
97
|
-
|
84
|
+
# control the client.
|
85
|
+
return drop_socket(socket) if socket.eof?
|
86
|
+
worker_name, worker_config = Marshal.load(socket)
|
87
|
+
client = @clients[socket]
|
88
|
+
client.name = worker_name
|
89
|
+
client.working = false
|
90
|
+
(@waiting_clients[worker_config] ||= []) << client
|
98
91
|
rescue SystemCallError, IOError => ex
|
99
92
|
logger.error("Receiving message from client (#{socket}) failed: #{ex.inspect}")
|
100
93
|
drop_socket(socket)
|
@@ -114,8 +107,10 @@ class ParentProcess
|
|
114
107
|
end
|
115
108
|
begin
|
116
109
|
client_timeout { Marshal.dump(job, client.socket) }
|
117
|
-
rescue SystemCallError, IOError, Timeout::Error
|
110
|
+
rescue SystemCallError, IOError, Timeout::Error => ex
|
111
|
+
logger.error("Failed to send pre-fetched job to #{client.name}: #{ex.inspect}")
|
118
112
|
drop_socket(client.socket)
|
113
|
+
Delayed::Job.unlock([job])
|
119
114
|
end
|
120
115
|
end
|
121
116
|
|
@@ -142,8 +137,10 @@ class ParentProcess
|
|
142
137
|
@waiting_clients[worker_config].delete(client)
|
143
138
|
begin
|
144
139
|
client_timeout { Marshal.dump(job, client.socket) }
|
145
|
-
rescue SystemCallError, IOError, Timeout::Error
|
140
|
+
rescue SystemCallError, IOError, Timeout::Error => ex
|
141
|
+
logger.error("Failed to send job to #{client.name}: #{ex.inspect}")
|
146
142
|
drop_socket(client.socket)
|
143
|
+
Delayed::Job.unlock([job])
|
147
144
|
end
|
148
145
|
end
|
149
146
|
end
|
@@ -20,7 +20,6 @@ RSpec.describe Delayed::WorkQueue::ParentProcess::Client do
|
|
20
20
|
|
21
21
|
it 'marshals the given arguments to the server and returns the response' do
|
22
22
|
expect(addrinfo).to receive(:connect).once.and_return(connection)
|
23
|
-
expect(connection).to receive(:wait_readable).with(10.0).and_return(connection)
|
24
23
|
expect(connection).to receive(:eof?).and_return(false)
|
25
24
|
expect(Marshal).to receive(:dump).with(args, connection).ordered
|
26
25
|
expect(Marshal).to receive(:load).with(connection).and_return(job).ordered
|
@@ -28,23 +27,6 @@ RSpec.describe Delayed::WorkQueue::ParentProcess::Client do
|
|
28
27
|
expect(response).to eq(job)
|
29
28
|
end
|
30
29
|
|
31
|
-
it 'returns nil and then reconnects on receive timeout' do
|
32
|
-
expect(addrinfo).to receive(:connect).once.and_return(connection)
|
33
|
-
expect(connection).to receive(:wait_readable).with(10.0).and_return(nil)
|
34
|
-
expect(Marshal).to receive(:dump).with(args, connection).ordered
|
35
|
-
expect(connection).to receive(:close)
|
36
|
-
response = subject.get_and_lock_next_available(*args)
|
37
|
-
expect(response).to be_nil
|
38
|
-
|
39
|
-
expect(addrinfo).to receive(:connect).once.and_return(connection)
|
40
|
-
expect(Marshal).to receive(:dump).with(args, connection)
|
41
|
-
expect(connection).to receive(:wait_readable).with(10.0).and_return(connection)
|
42
|
-
expect(connection).to receive(:eof?).and_return(false)
|
43
|
-
expect(Marshal).to receive(:load).with(connection).and_return(job)
|
44
|
-
response = subject.get_and_lock_next_available(*args)
|
45
|
-
expect(response).to eq(job)
|
46
|
-
end
|
47
|
-
|
48
30
|
it 'returns nil and then reconnects on socket write error' do
|
49
31
|
expect(addrinfo).to receive(:connect).once.and_return(connection)
|
50
32
|
expect(Marshal).to receive(:dump).and_raise(SystemCallError.new("failure"))
|
@@ -54,7 +36,6 @@ RSpec.describe Delayed::WorkQueue::ParentProcess::Client do
|
|
54
36
|
|
55
37
|
expect(addrinfo).to receive(:connect).once.and_return(connection)
|
56
38
|
expect(Marshal).to receive(:dump).with(args, connection)
|
57
|
-
expect(connection).to receive(:wait_readable).with(10.0).and_return(connection)
|
58
39
|
expect(connection).to receive(:eof?).and_return(false)
|
59
40
|
expect(Marshal).to receive(:load).with(connection).and_return(job)
|
60
41
|
response = subject.get_and_lock_next_available(*args)
|
@@ -63,7 +44,6 @@ RSpec.describe Delayed::WorkQueue::ParentProcess::Client do
|
|
63
44
|
|
64
45
|
it 'returns nil and then reconnects when the socket indicates eof' do
|
65
46
|
expect(addrinfo).to receive(:connect).once.and_return(connection)
|
66
|
-
expect(connection).to receive(:wait_readable).with(10.0).and_return(true)
|
67
47
|
expect(connection).to receive(:eof?).and_return(true)
|
68
48
|
expect(Marshal).to receive(:dump).with(args, connection).ordered
|
69
49
|
expect(connection).to receive(:close)
|
@@ -72,7 +52,6 @@ RSpec.describe Delayed::WorkQueue::ParentProcess::Client do
|
|
72
52
|
|
73
53
|
expect(addrinfo).to receive(:connect).once.and_return(connection)
|
74
54
|
expect(Marshal).to receive(:dump).with(args, connection)
|
75
|
-
expect(connection).to receive(:wait_readable).with(10.0).and_return(connection)
|
76
55
|
expect(connection).to receive(:eof?).and_return(false)
|
77
56
|
expect(Marshal).to receive(:load).with(connection).and_return(job)
|
78
57
|
response = subject.get_and_lock_next_available(*args)
|
@@ -83,7 +62,6 @@ RSpec.describe Delayed::WorkQueue::ParentProcess::Client do
|
|
83
62
|
expect(addrinfo).to receive(:connect).once.and_return(connection)
|
84
63
|
expect(Marshal).to receive(:dump).with(args, connection)
|
85
64
|
expect(Marshal).to receive(:load).with(connection).and_return(:not_a_job)
|
86
|
-
expect(connection).to receive(:wait_readable).with(10.0).and_return(connection)
|
87
65
|
expect(connection).to receive(:eof?).and_return(false)
|
88
66
|
|
89
67
|
expect { subject.get_and_lock_next_available(*args) }.to raise_error(Delayed::WorkQueue::ParentProcess::ProtocolError)
|
@@ -94,7 +72,6 @@ RSpec.describe Delayed::WorkQueue::ParentProcess::Client do
|
|
94
72
|
expect(Marshal).to receive(:dump).with(args, connection)
|
95
73
|
job.locked_by = "somebody_else"
|
96
74
|
expect(Marshal).to receive(:load).with(connection).and_return(job)
|
97
|
-
expect(connection).to receive(:wait_readable).with(10.0).and_return(connection)
|
98
75
|
expect(connection).to receive(:eof?).and_return(false)
|
99
76
|
|
100
77
|
expect { subject.get_and_lock_next_available(*args) }.to raise_error(Delayed::WorkQueue::ParentProcess::ProtocolError)
|
@@ -107,7 +107,7 @@ RSpec.describe Delayed::WorkQueue::ParentProcess::Server do
|
|
107
107
|
expect { subject.run_once }.to change(subject, :connected_clients).by(-1)
|
108
108
|
end
|
109
109
|
|
110
|
-
it 'drops the client
|
110
|
+
it 'drops the client when the client disconnects' do
|
111
111
|
client = Socket.unix(subject.listen_socket.local_address.unix_path)
|
112
112
|
subject.run_once
|
113
113
|
|
@@ -115,7 +115,7 @@ RSpec.describe Delayed::WorkQueue::ParentProcess::Server do
|
|
115
115
|
|
116
116
|
server_client_socket = subject.clients.keys.first
|
117
117
|
|
118
|
-
expect(server_client_socket).to receive(:
|
118
|
+
expect(server_client_socket).to receive(:eof?).and_return(true)
|
119
119
|
expect { subject.run_once }.to change(subject, :connected_clients).by(-1)
|
120
120
|
end
|
121
121
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: inst-jobs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.13.
|
4
|
+
version: 0.13.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tobias Luetke
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2017-04-
|
12
|
+
date: 2017-04-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: after_transaction_commit
|