madvertise-ext 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,6 @@
1
1
  # @private
2
2
  module Madvertise
3
3
  module Ext
4
- VERSION = "0.3.0"
4
+ VERSION = "0.4.0"
5
5
  end
6
6
  end
@@ -0,0 +1,39 @@
1
+ # encoding: utf-8
2
+
3
+ require 'eventmachine'
4
+ require 'servolux'
5
+ require 'thread'
6
+
7
+ module Servolux
8
+ class EventMachineServer < Server
9
+
10
+ def initialize(name, opts = {})
11
+ super
12
+ EventMachine.error_handler do |e|
13
+ $log.exception(e)
14
+ raise e
15
+ end
16
+ end
17
+
18
+ def before_starting
19
+ @reactor = Thread.new do
20
+ begin
21
+ EventMachine.run { boot if respond_to?(:boot) }
22
+ rescue => e
23
+ $log.exception(e)
24
+ end
25
+ end
26
+ end
27
+
28
+ def after_stopping
29
+ $log.debug("eventmachine stop")
30
+ EventMachine.stop_event_loop if EventMachine.reactor_running?
31
+ @reactor.kill
32
+ @reactor.join if @reactor.is_a?(Thread)
33
+ end
34
+
35
+ def run
36
+ end
37
+
38
+ end
39
+ end
@@ -5,38 +5,38 @@ require 'servolux'
5
5
  require 'servolux/cli'
6
6
 
7
7
  module Servolux
8
- def self.init_config(cli_class)
9
- config = cli_class.parse_options
8
+ def self.parse_opts(cli_class)
9
+ opts = cli_class.parse_options
10
10
 
11
11
  # CLI.parse_options may have changed $0
12
12
  # so we reload the logger for good measure
13
13
  $log = init_logger
14
- $log.level = config[:debug] ? :debug : :info
14
+ $log.level = opts[:debug] ? :debug : :info
15
15
 
16
- return config
16
+ return opts
17
17
  end
18
18
 
19
19
  def self.wrap(server_class)
20
- config = self.init_config(Servolux::CLI)
21
- server_class.new(config).run
20
+ opts = self.parse_opts(Servolux::CLI)
21
+ server_class.new(opts).run
22
22
  rescue => e
23
23
  $log.exception(e)
24
24
  raise e
25
25
  end
26
26
 
27
27
  def self.wrap_daemon(server_class)
28
- config = self.init_config(Servolux::DaemonCLI)
28
+ opts = self.parse_opts(Servolux::DaemonCLI)
29
29
 
30
- server = server_class.new(config[:name], config.merge({
30
+ server = server_class.new(opts[:name], opts.merge({
31
31
  interval: 1,
32
32
  logger: $log,
33
- pid_file: config[:pidfile]
33
+ pid_file: opts[:pidfile]
34
34
  }))
35
35
 
36
- if config[:daemonize] or config[:kill]
36
+ if opts[:daemonize] or opts[:kill]
37
37
  daemon = Servolux::Daemon.new(:server => server)
38
38
 
39
- if config[:kill]
39
+ if opts[:kill]
40
40
  daemon.shutdown
41
41
  else
42
42
  daemon.startup
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: madvertise-ext
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
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: 2013-01-02 00:00:00.000000000 Z
12
+ date: 2013-01-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: madvertise-logging
@@ -86,6 +86,7 @@ files:
86
86
  - lib/madvertise/ext/transaction_id.rb
87
87
  - lib/madvertise/ext/version.rb
88
88
  - lib/servolux/cli.rb
89
+ - lib/servolux/eventmachine.rb
89
90
  - lib/servolux/wrapper.rb
90
91
  - madvertise-ext.gemspec
91
92
  - spec/enumerable_spec.rb
@@ -108,7 +109,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
108
109
  version: '0'
109
110
  segments:
110
111
  - 0
111
- hash: -2076914703053798103
112
+ hash: 1335580830932580809
112
113
  required_rubygems_version: !ruby/object:Gem::Requirement
113
114
  none: false
114
115
  requirements:
@@ -117,7 +118,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
117
118
  version: '0'
118
119
  segments:
119
120
  - 0
120
- hash: -2076914703053798103
121
+ hash: 1335580830932580809
121
122
  requirements: []
122
123
  rubyforge_project:
123
124
  rubygems_version: 1.8.24