resque-multi-job-forks 0.4.5 → 0.5.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/resque-multi-job-forks.rb +27 -18
- data/test/helper.rb +5 -3
- data/test/test_resque-multi-job-forks.rb +21 -8
- metadata +13 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7cb28f2bcae133394c2e1a4e2cd71c256030fdefcb86dfb9c3300913056a9324
|
4
|
+
data.tar.gz: a2a002cc266e7c42ac9e92388ea2837392e697b3a27aa4d033577223f3900596
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a66af847f0dece95ba2e0990433d5dfde52cee08b51b9163f3551269d5c8fd0bc31c2207a45aad23a3d1af19e065482c5871afd4f7014bcd58f10d2b24dae9db
|
7
|
+
data.tar.gz: 5acdcd7e2b3eb9ee375852a6d3539016994e0344a57b1256e33bacaf533fce2fb89c088f3fb7dfb2b96002e10bd8930c9161b9591b17cafced036eb8ae13ae75
|
@@ -15,6 +15,20 @@ module Resque
|
|
15
15
|
end
|
16
16
|
|
17
17
|
if multi_jobs_per_fork? && !method_defined?(:shutdown_without_multi_job_forks)
|
18
|
+
|
19
|
+
def fork(&block)
|
20
|
+
if child = Kernel.fork
|
21
|
+
return child
|
22
|
+
else
|
23
|
+
if term_child
|
24
|
+
unregister_signal_handlers
|
25
|
+
trap('QUIT') { shutdown }
|
26
|
+
end
|
27
|
+
raise NotImplementedError, "Pretending to not have forked"
|
28
|
+
# perform_with_fork will run the job and continue working...
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
18
32
|
def work_with_multi_job_forks(*args)
|
19
33
|
pid # forces @pid to be set in the parent
|
20
34
|
work_without_multi_job_forks(*args)
|
@@ -24,7 +38,7 @@ module Resque
|
|
24
38
|
alias_method :work, :work_with_multi_job_forks
|
25
39
|
|
26
40
|
def perform_with_multi_job_forks(job = nil)
|
27
|
-
|
41
|
+
@fork_per_job = true unless fork_hijacked? # reconnect and after_fork
|
28
42
|
perform_without_multi_job_forks(job)
|
29
43
|
hijack_fork unless fork_hijacked?
|
30
44
|
@jobs_processed += 1
|
@@ -40,14 +54,14 @@ module Resque
|
|
40
54
|
alias_method :shutdown?, :shutdown_with_multi_job_forks?
|
41
55
|
|
42
56
|
def shutdown_with_multi_job_forks
|
43
|
-
shutdown_child
|
57
|
+
shutdown_child
|
44
58
|
shutdown_without_multi_job_forks
|
45
59
|
end
|
46
60
|
alias_method :shutdown_without_multi_job_forks, :shutdown
|
47
61
|
alias_method :shutdown, :shutdown_with_multi_job_forks
|
48
62
|
|
49
63
|
def pause_processing_with_multi_job_forks
|
50
|
-
shutdown_child
|
64
|
+
shutdown_child
|
51
65
|
pause_processing_without_multi_job_forks
|
52
66
|
end
|
53
67
|
alias_method :pause_processing_without_multi_job_forks, :pause_processing
|
@@ -75,8 +89,9 @@ module Resque
|
|
75
89
|
# multiple jobs per fork. The QUIT signal normally does a graceful shutdown,
|
76
90
|
# and is re-registered in children (term_child normally unregisters it).
|
77
91
|
def shutdown_child
|
92
|
+
return unless @child
|
78
93
|
begin
|
79
|
-
|
94
|
+
log_with_severity :debug, "multi_jobs_per_fork: Sending QUIT signal to #{@child}"
|
80
95
|
Process.kill('QUIT', @child)
|
81
96
|
rescue Errno::ESRCH
|
82
97
|
nil
|
@@ -97,22 +112,21 @@ module Resque
|
|
97
112
|
end
|
98
113
|
|
99
114
|
def hijack_fork
|
100
|
-
|
115
|
+
log_with_severity :debug, 'hijack fork.'
|
101
116
|
@suppressed_fork_hooks = [Resque.after_fork, Resque.before_fork]
|
102
117
|
Resque.after_fork = Resque.before_fork = nil
|
103
118
|
@release_fork_limit = fork_job_limit
|
104
119
|
@jobs_processed = 0
|
105
|
-
@
|
106
|
-
trap('QUIT') { shutdown }
|
120
|
+
@fork_per_job = false
|
107
121
|
end
|
108
122
|
|
109
123
|
def release_fork
|
110
|
-
|
124
|
+
log_with_severity :info, "jobs processed by child: #{jobs_processed}; rss: #{rss}"
|
111
125
|
run_hook :before_child_exit, self
|
112
126
|
Resque.after_fork, Resque.before_fork = *@suppressed_fork_hooks
|
113
|
-
@release_fork_limit = @jobs_processed =
|
114
|
-
|
115
|
-
@shutdown = true
|
127
|
+
@release_fork_limit = @jobs_processed = nil
|
128
|
+
log_with_severity :debug, 'hijack over, counter terrorists win.'
|
129
|
+
@shutdown = true
|
116
130
|
end
|
117
131
|
|
118
132
|
def fork_job_limit
|
@@ -156,16 +170,11 @@ module Resque
|
|
156
170
|
# Call with a block to set the hook.
|
157
171
|
# Call with no arguments to return the hook.
|
158
172
|
def self.before_child_exit(&block)
|
159
|
-
|
160
|
-
@before_child_exit ||= []
|
161
|
-
@before_child_exit << block
|
162
|
-
end
|
163
|
-
@before_child_exit
|
173
|
+
block ? register_hook(:before_child_exit, block) : hooks(:before_child_exit)
|
164
174
|
end
|
165
175
|
|
166
176
|
# Set the before_child_exit proc.
|
167
177
|
def self.before_child_exit=(before_child_exit)
|
168
|
-
|
178
|
+
register_hook(:before_child_exit, block)
|
169
179
|
end
|
170
|
-
|
171
180
|
end
|
data/test/helper.rb
CHANGED
@@ -20,10 +20,12 @@ Resque.redis = $redis
|
|
20
20
|
module Resque
|
21
21
|
class Worker
|
22
22
|
|
23
|
-
def
|
24
|
-
|
23
|
+
def log_with_severity(severity, msg)
|
24
|
+
if ENV['VERBOSE']
|
25
|
+
s = severity.to_s[0].upcase
|
26
|
+
$stderr.print "*** [#{Time.now}] [#{Process.pid}] #{self} #{s}: #{msg}\n"
|
27
|
+
end
|
25
28
|
end
|
26
|
-
alias_method :log!, :log
|
27
29
|
|
28
30
|
end
|
29
31
|
end
|
@@ -8,6 +8,7 @@ class TestResqueMultiJobForks < Test::Unit::TestCase
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def test_timeout_limit_sequence_of_events
|
11
|
+
@worker.log_with_severity :debug, "in test_timeout_limit_sequence_of_events"
|
11
12
|
# only allow enough time for 3 jobs to process.
|
12
13
|
@worker.seconds_per_fork = 3
|
13
14
|
|
@@ -28,6 +29,7 @@ class TestResqueMultiJobForks < Test::Unit::TestCase
|
|
28
29
|
end
|
29
30
|
|
30
31
|
def test_graceful_shutdown_during_first_job
|
32
|
+
@worker.log_with_severity :debug, "in test_graceful_shutdown_during_first_job"
|
31
33
|
# enough time for all jobs to process.
|
32
34
|
@worker.seconds_per_fork = 60
|
33
35
|
|
@@ -49,6 +51,7 @@ class TestResqueMultiJobForks < Test::Unit::TestCase
|
|
49
51
|
end
|
50
52
|
|
51
53
|
def test_immediate_shutdown_during_first_job
|
54
|
+
@worker.log_with_severity :debug, "in test_immediate_shutdown_during_first_job"
|
52
55
|
# enough time for all jobs to process.
|
53
56
|
@worker.seconds_per_fork = 60
|
54
57
|
@worker.term_child = false
|
@@ -70,6 +73,7 @@ class TestResqueMultiJobForks < Test::Unit::TestCase
|
|
70
73
|
end
|
71
74
|
|
72
75
|
def test_sigterm_shutdown_during_first_job
|
76
|
+
@worker.log_with_severity :debug, "in test_sigterm_shutdown_during_first_job"
|
73
77
|
# enough time for all jobs to process.
|
74
78
|
@worker.seconds_per_fork = 60
|
75
79
|
@worker.term_child = true
|
@@ -94,6 +98,7 @@ class TestResqueMultiJobForks < Test::Unit::TestCase
|
|
94
98
|
|
95
99
|
# test we can also limit fork job process by a job limit.
|
96
100
|
def test_job_limit_sequence_of_events
|
101
|
+
@worker.log_with_severity :debug, "in test_job_limit_sequence_of_events"
|
97
102
|
# only allow 20 jobs per fork
|
98
103
|
ENV['JOBS_PER_FORK'] = '20'
|
99
104
|
|
@@ -105,18 +110,26 @@ class TestResqueMultiJobForks < Test::Unit::TestCase
|
|
105
110
|
$SEQ_WRITER.close
|
106
111
|
sequence = $SEQ_READER.each_line.map {|l| l.strip.to_sym }
|
107
112
|
|
108
|
-
assert_equal
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
113
|
+
assert_equal(%i[
|
114
|
+
before_fork after_fork
|
115
|
+
work_1 work_2 work_3 work_4 work_5
|
116
|
+
work_6 work_7 work_8 work_9 work_10
|
117
|
+
work_11 work_12 work_13 work_14 work_15
|
118
|
+
work_16 work_17 work_18 work_19 work_20
|
119
|
+
before_child_exit_20
|
120
|
+
before_fork after_fork
|
121
|
+
work_21 work_22 work_23 work_24 work_25
|
122
|
+
work_26 work_27 work_28 work_29 work_30
|
123
|
+
work_31 work_32 work_33 work_34 work_35
|
124
|
+
work_36 work_37 work_38 work_39 work_40
|
125
|
+
before_child_exit_20
|
126
|
+
], sequence, 'correct sequence')
|
116
127
|
end
|
117
128
|
|
118
129
|
def teardown
|
119
130
|
# make sure we don't clobber any other tests.
|
120
131
|
ENV['JOBS_PER_FORK'] = nil
|
132
|
+
Resque::Worker.kill_all_heartbeat_threads
|
121
133
|
end
|
134
|
+
|
122
135
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: resque-multi-job-forks
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mick Staugaard
|
@@ -10,22 +10,28 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2021-08-17 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: resque
|
17
17
|
requirement: !ruby/object:Gem::Requirement
|
18
18
|
requirements:
|
19
|
-
- - "
|
19
|
+
- - ">="
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 1.27.0
|
22
|
+
- - "<"
|
20
23
|
- !ruby/object:Gem::Version
|
21
|
-
version:
|
24
|
+
version: '2.2'
|
22
25
|
type: :runtime
|
23
26
|
prerelease: false
|
24
27
|
version_requirements: !ruby/object:Gem::Requirement
|
25
28
|
requirements:
|
26
|
-
- - "
|
29
|
+
- - ">="
|
30
|
+
- !ruby/object:Gem::Version
|
31
|
+
version: 1.27.0
|
32
|
+
- - "<"
|
27
33
|
- !ruby/object:Gem::Version
|
28
|
-
version:
|
34
|
+
version: '2.2'
|
29
35
|
- !ruby/object:Gem::Dependency
|
30
36
|
name: json
|
31
37
|
requirement: !ruby/object:Gem::Requirement
|
@@ -115,7 +121,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
115
121
|
- !ruby/object:Gem::Version
|
116
122
|
version: '0'
|
117
123
|
requirements: []
|
118
|
-
rubygems_version: 3.
|
124
|
+
rubygems_version: 3.1.4
|
119
125
|
signing_key:
|
120
126
|
specification_version: 4
|
121
127
|
summary: Have your resque workers process more that one job
|