perfectqueue 0.8.10 → 0.8.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/ChangeLog CHANGED
@@ -1,4 +1,11 @@
1
1
 
2
+ == 2012-08-05 version 0.8.11
3
+
4
+ * Support child_fork_frequency_limit option to wait before forking child
5
+ * Error messages include processor id and pid
6
+ * Don't check child process status if it's killing status is immediate-killing
7
+
8
+
2
9
  == 2012-08-04 version 0.8.10
3
10
 
4
11
  * rdb_backend returns max_running attribute
@@ -33,6 +33,8 @@ module PerfectQueue
33
33
  @rbuf = ''
34
34
  end
35
35
 
36
+ attr_reader :pid
37
+
36
38
  def check_heartbeat(limit)
37
39
  @rpipe.read_nonblock(1024, @rbuf)
38
40
  @last_heartbeat = Time.now.to_i
@@ -53,6 +55,18 @@ module PerfectQueue
53
55
  @kill_start_time = now
54
56
  end
55
57
 
58
+ def killing_status
59
+ if @kill_start_time
60
+ if @kill_immediate
61
+ return true
62
+ else
63
+ return false
64
+ end
65
+ else
66
+ return nil
67
+ end
68
+ end
69
+
56
70
  def try_join(kill_interval, graceful_kill_limit)
57
71
  return nil unless @kill_start_time
58
72
 
@@ -27,6 +27,7 @@ module PerfectQueue
27
27
  require 'fcntl'
28
28
  @stop = false
29
29
  @cpm = nil
30
+ @last_fork_time = 0
30
31
 
31
32
  restart(false, config)
32
33
  end
@@ -35,6 +36,7 @@ module PerfectQueue
35
36
  @child_heartbeat_limit = config[:child_heartbeat_limit] || 10.0
36
37
  @child_kill_interval = config[:child_kill_interval] || 2.0
37
38
  @child_graceful_kill_limit = config[:child_graceful_kill_limit] || nil
39
+ @child_fork_frequency_limit = config[:child_fork_frequency_limit] || 5.0
38
40
  @log = config[:logger]
39
41
  @config = config # for child process
40
42
 
@@ -58,20 +60,23 @@ module PerfectQueue
58
60
  end
59
61
 
60
62
  if c = @cpm
61
- begin
62
- # receive heartbeat
63
- keptalive = c.check_heartbeat(@child_heartbeat_limit)
64
- unless keptalive
65
- @log.error "Heartbeat broke out. Restarting child process."
63
+ if c.killing_status != true
64
+ # don't check status if killing status is immediate-killing
65
+ begin
66
+ # receive heartbeat
67
+ keptalive = c.check_heartbeat(@child_heartbeat_limit)
68
+ if !keptalive
69
+ @log.error "Heartbeat broke out. Restarting child process id=#{@processor_id} pid=#{c.pid}."
70
+ c.start_killing(true)
71
+ end
72
+ rescue EOFError
73
+ @log.error "Heartbeat pipe is closed. Restarting child process id=#{@processor_id} pid=#{c.pid}."
74
+ c.start_killing(true)
75
+ rescue
76
+ @log.error "Unknown error: #{$!.class}: #{$!}: Restarting child process id=#{@processor_id} pid=#{c.pid}."
77
+ $!.backtrace.each {|bt| @log.warn "\t#{bt}" }
66
78
  c.start_killing(false)
67
79
  end
68
- rescue EOFError
69
- @log.error "Heartbeat pipe is closed. Restarting child process."
70
- c.start_killing(true)
71
- rescue
72
- @log.error "Unknown error: #{$!.class}: #{$!}: Restarting child process."
73
- $!.backtrace.each {|bt| @log.warn "\t#{bt}" }
74
- c.start_killing(false)
75
80
  end
76
81
 
77
82
  try_join
@@ -81,7 +86,7 @@ module PerfectQueue
81
86
  begin
82
87
  @cpm = fork_child
83
88
  rescue
84
- @log.error "Failed to fork child process: #{$!.class}: #{$!}"
89
+ @log.error "Failed to fork child process id=#{@processor_id}: #{$!.class}: #{$!}"
85
90
  $!.backtrace.each {|bt| @log.warn "\t#{bt}" }
86
91
  end
87
92
  end
@@ -116,15 +121,16 @@ module PerfectQueue
116
121
  end
117
122
  end
118
123
 
119
- def ensure_fork
120
- unless @cpm
121
- @cpm = fork_child
122
- end
123
- end
124
-
125
124
  INTER_FORK_LOCK = Mutex.new
126
125
 
127
126
  def fork_child
127
+ now = Time.now.to_f
128
+ if now - @last_fork_time < @child_fork_frequency_limit
129
+ @log.info "Tried to fork child #{now-@last_fork_time} seconds ago < #{@child_fork_frequency_limit}. Waiting... id=#{@processor_id}"
130
+ return nil
131
+ end
132
+ @last_fork_time = now
133
+
128
134
  # set process name
129
135
  @runner.before_fork if @runner.respond_to?(:before_fork) # TODO exception handling
130
136
 
@@ -69,7 +69,7 @@ module PerfectQueue
69
69
  end
70
70
 
71
71
  def stop(immediate)
72
- @log.info immediate ? "Stopping worker thread immediately" : "Stopping worker thread gracefully"
72
+ @log.info immediate ? "Stopping worker thread immediately id=#{@processor_id}" : "Stopping worker thread gracefully id=#{@processor_id}"
73
73
  @tm.stop_task(immediate)
74
74
  @finish_flag.set!
75
75
  end
@@ -95,14 +95,14 @@ module PerfectQueue
95
95
  end
96
96
  }
97
97
  rescue
98
- @log.error "Unknown error #{$!.class}: #{$!}: Exiting worker pid=#{Process.pid}"
98
+ @log.error "Unknown error #{$!.class}: #{$!}: Exiting worker id=#{@processor_id}"
99
99
  $!.backtrace.each {|bt| @log.warn "\t#{bt}" }
100
100
  ensure
101
101
  @tm.stop
102
102
  end
103
103
 
104
104
  def process(task)
105
- @log.info "acquired task: #{task.inspect}"
105
+ @log.info "acquired task id=#{@processor_id}: #{task.inspect}"
106
106
  begin
107
107
  r = @runner.new(task)
108
108
  @tm.set_task(task, r)
@@ -112,7 +112,7 @@ module PerfectQueue
112
112
  @tm.task_finished(task)
113
113
  end
114
114
  rescue
115
- @log.error "process failed: #{$!.class}: #{$!}"
115
+ @log.error "process failed id=#{@processor_id}: #{$!.class}: #{$!}"
116
116
  $!.backtrace.each {|bt| @log.warn "\t#{bt}" }
117
117
  raise # force exit
118
118
  end
@@ -1,3 +1,3 @@
1
1
  module PerfectQueue
2
- VERSION = "0.8.10"
2
+ VERSION = "0.8.11"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: perfectqueue
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.10
4
+ version: 0.8.11
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-04 00:00:00.000000000 Z
12
+ date: 2012-08-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sequel