perfectqueue 0.8.14 → 0.8.15

Sign up to get free protection for your applications and to get access to all the features.
data/ChangeLog CHANGED
@@ -1,4 +1,9 @@
1
1
 
2
+ == 2012-08-30 version 0.8.15
3
+
4
+ * Improved detach process routines
5
+
6
+
2
7
  == 2012-08-16 version 0.8.14
3
8
 
4
9
  * Improved detach process routines
@@ -12,6 +12,7 @@ commands:
12
12
  force_finish <key> Force finish a task
13
13
  run <class> Run a worker process
14
14
  init Initialize a backend database
15
+ debug <address> Connect to debug interface of a worker
15
16
 
16
17
  ]
17
18
  op.version = PerfectQueue::VERSION
@@ -20,6 +21,7 @@ env = ENV['RAILS_ENV'] || 'development'
20
21
  config_path = 'config/perfectqueue.yml'
21
22
  include_dirs = []
22
23
  require_files = []
24
+ debug_listen = nil
23
25
 
24
26
  task_options = {
25
27
  }
@@ -100,6 +102,11 @@ begin
100
102
  cmd = :init
101
103
  usage nil unless ARGV.length == 0
102
104
 
105
+ when 'debug'
106
+ cmd = :debug
107
+ usage nil unless ARGV.length == 1
108
+ debug_address = ARGV[0]
109
+
103
110
  else
104
111
  raise "unknown command: '#{cmd}'"
105
112
  end
@@ -163,5 +170,28 @@ when :init
163
170
  PerfectQueue.open(config_load_proc.call) {|queue|
164
171
  queue.client.init_database
165
172
  }
173
+
174
+ when :debug
175
+ require 'irb'
176
+ require 'drb'
177
+ if debug_address.include?('/')
178
+ # unix
179
+ require 'drb/unix'
180
+ uri = "drbunix:#{debug_address}"
181
+ else
182
+ # tcp
183
+ uri = "druby://#{debug_address}"
184
+ end
185
+
186
+ puts "Connecting to #{uri}"
187
+
188
+ remote_supervisor = DRb::DRbObject.new_with_uri(uri)
189
+ Supervisor = remote_supervisor
190
+ Engine = remote_supervisor.engine
191
+
192
+ puts "Engine is initialized as a remote engine instance."
193
+
194
+ ARGV.clear
195
+ IRB.start
166
196
  end
167
197
 
@@ -38,6 +38,8 @@ module PerfectQueue
38
38
  restart(false, config)
39
39
  end
40
40
 
41
+ attr_reader :processors
42
+
41
43
  def restart(immediate, config)
42
44
  return nil if @finish_flag.set?
43
45
 
@@ -33,11 +33,15 @@ module PerfectQueue
33
33
  @config_load_proc = block
34
34
  end
35
35
 
36
+ attr_reader :engine
37
+
36
38
  def run
37
39
  @log.info "PerfectQueue #{VERSION}"
38
40
 
39
41
  install_signal_handlers do
40
- @engine = Engine.new(@runner, load_config)
42
+ config = load_config
43
+ @engine = Engine.new(@runner, config)
44
+ listen_debug_server(config)
41
45
  begin
42
46
  @engine.run
43
47
  ensure
@@ -111,6 +115,31 @@ module PerfectQueue
111
115
  return config
112
116
  end
113
117
 
118
+ def listen_debug_server(config)
119
+ address = config[:debug].to_s
120
+ return if address.empty?
121
+
122
+ require 'drb'
123
+ if address.include?('/')
124
+ # unix
125
+ require 'drb/unix'
126
+ uri = "drbunix:#{address}"
127
+ if File.exist?(address)
128
+ File.unlink(address) rescue nil
129
+ end
130
+ else
131
+ # tcp
132
+ a, b = address.split(':',2)
133
+ if b
134
+ uri = "druby://#{a}:#{b}"
135
+ else
136
+ uri = "druby://0.0.0.0:#{a}"
137
+ end
138
+ end
139
+
140
+ @debug_server = DRb::DRbServer.new(uri, self)
141
+ end
142
+
114
143
  def install_signal_handlers(&block)
115
144
  sig = SignalQueue.start do |sig|
116
145
  sig.trap :TERM do
@@ -1,3 +1,3 @@
1
1
  module PerfectQueue
2
- VERSION = "0.8.14"
2
+ VERSION = "0.8.15"
3
3
  end
@@ -60,7 +60,7 @@ module PerfectQueue
60
60
  wait_time = Time.now + @detach_wait
61
61
  while (w = wait_time - Time.now) > 0
62
62
  sleep [1, w].max
63
- pid, status = Process.waitpid2(@pid)
63
+ pid, status = Process.waitpid2(@pid, Process::WNOHANG)
64
64
  break if pid
65
65
  end
66
66
 
@@ -73,7 +73,7 @@ module PerfectQueue
73
73
  end
74
74
 
75
75
  def stop(immediate)
76
- send_signal(immediate ? :TERM : :QUIT)
76
+ send_signal(immediate ? :QUIT : :TERM)
77
77
  end
78
78
 
79
79
  def restart(immediate)
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.14
4
+ version: 0.8.15
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-16 00:00:00.000000000 Z
12
+ date: 2012-08-31 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sequel