asir 1.1.5 → 1.1.6

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,3 +1,11 @@
1
+ 2012-12-07 Kurt A. Stephens <ks.github@kurtstephens.com>
2
+
3
+ * v1.1.6: New version.
4
+ * Conduit: handles :conduit_options, pid_file.
5
+ * Transport: added after_invoke_message callback.
6
+ * Main: handle --help option.
7
+ * Main: Don't close stdio stream till worker is running.
8
+
1
9
  2012-12-05 Kurt A. Stephens <ks.github@kurtstephens.com>
2
10
 
3
11
  * v1.1.5: New version.
@@ -34,6 +34,9 @@ class Main
34
34
  self.args = args
35
35
  until args.empty?
36
36
  case args.first
37
+ when /^--?h(elp)/
38
+ @help = true
39
+ return self
37
40
  when /^([a-z0-9_]+=)(.*)/i
38
41
  k, v = $1.to_sym, $2
39
42
  args.shift
@@ -61,6 +64,9 @@ class Main
61
64
  end
62
65
 
63
66
  def run!
67
+ if @help
68
+ return usage!
69
+ end
64
70
  unless verb && adjective && object
65
71
  self.exit_code = 1
66
72
  return usage!
@@ -172,6 +178,7 @@ EXAMPLES:
172
178
  asir start zmq worker 1
173
179
  asir start zmq worker 2
174
180
  END
181
+ self
175
182
  end
176
183
 
177
184
  def start_beanstalk_conduit!
@@ -193,11 +200,17 @@ END
193
200
  def _start_worker! type = adjective
194
201
  log "start_worker! #{type}"
195
202
  type = type.to_s
203
+ config!(:environment)
204
+ self.transport = config!(:transport)
205
+
206
+ # Get the expected transport class.
207
+ transport_file = "asir/transport/#{type}"
208
+ log "loading #{transport_file}"
209
+ require transport_file
210
+ transport_class = ASIR::Transport.const_get(type[0..0].upcase + type[1..-1])
211
+
196
212
  fork_server! do
197
- transport_file = "asir/transport/#{type}"
198
- log "loading #{transport_file}"
199
- require transport_file
200
- _create_transport ASIR::Transport.const_get(type[0..0].upcase + type[1..-1])
213
+ _create_transport transport_class
201
214
  _run_workers!
202
215
  end
203
216
  end
@@ -111,6 +111,10 @@ module ASIR
111
111
  # trans.on_result_exception.call(trans, result)
112
112
  attr_accessor :on_result_exception
113
113
 
114
+ # Proc to call after #invoke_message!
115
+ # trans.after_invoke_message.call(trans, message, result)
116
+ attr_accessor :after_invoke_message
117
+
114
118
  # Proc to call with exception, if exception occurs within #serve_message!, but outside
115
119
  # Message#invoke!.
116
120
  #
@@ -142,6 +146,9 @@ module ASIR
142
146
  message_ok = true
143
147
  result = invoke_message!(message)
144
148
  result_ok = true
149
+ if @after_invoke_message
150
+ @after_invoke_message.call(self, message, result)
151
+ end
145
152
  self
146
153
  else
147
154
  nil
@@ -4,9 +4,11 @@ module Asir
4
4
  class Transport
5
5
  # Conduit service support.
6
6
  module Conduit
7
+ attr_accessor :conduit_options, :conduit_pid
7
8
  def start_conduit! options = nil
8
9
  opts = { :fork => true }
9
10
  opts.update(options) if options
11
+ @conduit_options = opts
10
12
  _log { "start_conduit! #{self}" } if @verbose >= 1
11
13
  in_fork = opts[:fork]
12
14
  raise "already running #{@conduit_pid} #{@conduit_cmd}" if @conduit_pid
@@ -17,18 +19,28 @@ module Asir
17
19
  raise "Could not exec"
18
20
  end
19
21
  _log { "start_conduit! #{self} started pid=#{@conduit_pid.inspect}" } if @verbose >= 2
22
+ if pid_file = @conduit_options[:pid_file]
23
+ File.open(pid_file, "w") { | fh | fh.puts @conduit_pid }
24
+ end
20
25
  else
21
26
  _start_conduit!
22
27
  end
23
28
  self
24
29
  end
25
30
 
31
+ def conduit_pid
32
+ if ! @conduit_pid and pid_file = @conduit_options[:pid_file]
33
+ @conduit_pid = (File.read(pid_file).to_i rescue nil)
34
+ end
35
+ @conduit_pid
36
+ end
37
+
26
38
  def stop_conduit! opts = nil
27
- if @conduit_pid
39
+ if conduit_pid
28
40
  _log { "stop_conduit! #{self} pid=#{@conduit_pid.inspect}" } if @verbose >= 1
29
41
  ::Process.kill( (opts && opts[:signal]) || 'TERM', @conduit_pid)
42
+ ::File.unlink(pid_file) rescue nil if pid_file
30
43
  ::Process.waitpid @conduit_pid
31
- # File.unlink @redis_conf
32
44
  end
33
45
  self
34
46
  ensure
@@ -1,3 +1,3 @@
1
1
  module ASIR
2
- VERSION = "1.1.5"
2
+ VERSION = "1.1.6"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: asir
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.5
4
+ version: 1.1.6
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-12-06 00:00:00.000000000 Z
12
+ date: 2012-12-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: uuid
@@ -314,7 +314,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
314
314
  version: '0'
315
315
  segments:
316
316
  - 0
317
- hash: -3496337274665454137
317
+ hash: 4585865116450200509
318
318
  required_rubygems_version: !ruby/object:Gem::Requirement
319
319
  none: false
320
320
  requirements:
@@ -323,7 +323,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
323
323
  version: '0'
324
324
  segments:
325
325
  - 0
326
- hash: -3496337274665454137
326
+ hash: 4585865116450200509
327
327
  requirements: []
328
328
  rubyforge_project:
329
329
  rubygems_version: 1.8.24