resque-multi-job-forks 0.4.5 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA256:
3
- metadata.gz: e14fad0b41eaab14a736ac76d9e234314c97279b190d90ab935a74717bc18921
4
- data.tar.gz: fc1a9a67f6a6825180044316144b70923f771d454e5c6338c86ccd22aecb3fb8
2
+ SHA1:
3
+ metadata.gz: 2bd1e8435173c27eefcab09cdc99cba876698404
4
+ data.tar.gz: 96f8db0967c05a3104fc48e78fa49f5a0c5c4e79
5
5
  SHA512:
6
- metadata.gz: 2da4375dc2b26da0c670e402954c0b5496a6ce46c3100eabe4f9991d50cd987b0c8d4e5745fdb72f1632f35934f112eb42df6a141c7d838904ed12419f0e8a7d
7
- data.tar.gz: cc8c72fa05245eae3aa8a19811b54279ee00f6257fb8093942c9fd7c8d62336fb4ce1e7242de96e997772baff15486838cd3418ca0436d21ec38dd6f4cb4a3fe
6
+ metadata.gz: 91ffc7a44dcb0353754bcc96410ed3d4c4701d3176427dfa8b626d5b6a3af3eb1ce3a1d5e8a6f5d39809e661de98121ba39d6d08fd17b5d550adb0731312fb44
7
+ data.tar.gz: 8bca3021d289308c02d199e30a7dea8551ca8103783effe134ab71dc641894ebd4ae727320a5551e3611357f786db2cb84a65872e74bf0130937d67735da4cae
@@ -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
- trap('QUIT') { shutdown } unless fork_hijacked?
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
@@ -102,17 +116,16 @@ module Resque
102
116
  Resque.after_fork = Resque.before_fork = nil
103
117
  @release_fork_limit = fork_job_limit
104
118
  @jobs_processed = 0
105
- @cant_fork = true
106
- trap('QUIT') { shutdown }
119
+ @fork_per_job = false
107
120
  end
108
121
 
109
122
  def release_fork
110
123
  log "jobs processed by child: #{jobs_processed}; rss: #{rss}"
111
124
  run_hook :before_child_exit, self
112
125
  Resque.after_fork, Resque.before_fork = *@suppressed_fork_hooks
113
- @release_fork_limit = @jobs_processed = @cant_fork = nil
126
+ @release_fork_limit = @jobs_processed = nil
114
127
  log 'hijack over, counter terrorists win.'
115
- @shutdown = true unless $TESTING
128
+ @shutdown = true
116
129
  end
117
130
 
118
131
  def fork_job_limit
@@ -20,10 +20,20 @@ Resque.redis = $redis
20
20
  module Resque
21
21
  class Worker
22
22
 
23
- def log(msg)
24
- puts "*** #{msg}" unless ENV['VERBOSE'].nil?
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
28
+ end
29
+
30
+ def log(message)
31
+ log_with_severity :info, message
32
+ end
33
+
34
+ def log!(message)
35
+ log_with_severity :debug, message
25
36
  end
26
- alias_method :log!, :log
27
37
 
28
38
  end
29
39
  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! "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! "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! "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! "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! "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 :before_fork, sequence[0], 'first before_fork call.'
109
- assert_equal :after_fork, sequence[1], 'first after_fork call.'
110
- assert_equal :work_20, sequence[21], '20th chunk of work.'
111
- assert_equal :before_child_exit_20, sequence[22], 'first before_child_exit call.'
112
- assert_equal :before_fork, sequence[23], 'final before_fork call.'
113
- assert_equal :after_fork, sequence[24], 'final after_fork call.'
114
- assert_equal :work_40, sequence[44], '40th chunk of work.'
115
- assert_equal :before_child_exit_20, sequence[45], 'final before_child_exit call.'
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.5
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mick Staugaard
@@ -16,16 +16,22 @@ dependencies:
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: 1.26.0
24
+ version: '2.1'
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: 1.26.0
34
+ version: '2.1'
29
35
  - !ruby/object:Gem::Dependency
30
36
  name: json
31
37
  requirement: !ruby/object:Gem::Requirement
@@ -115,7 +121,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
115
121
  - !ruby/object:Gem::Version
116
122
  version: '0'
117
123
  requirements: []
118
- rubygems_version: 3.0.1
124
+ rubyforge_project:
125
+ rubygems_version: 2.6.14.3
119
126
  signing_key:
120
127
  specification_version: 4
121
128
  summary: Have your resque workers process more that one job