run_rabbit_run 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -20,7 +20,7 @@ module RunRabbitRun
20
20
  raise "The process [#{@name}] is already running"
21
21
  end
22
22
 
23
- RunRabbitRun.logger.info "[#{@name}] process starting"
23
+ RunRabbitRun.local_logger.info "[#{@name}] process starting"
24
24
 
25
25
  @pid = fork do
26
26
  $0 = "[ruby] [RunRabbitRun] #{@name}"
@@ -52,7 +52,7 @@ module RunRabbitRun
52
52
  @starting = false
53
53
  end
54
54
 
55
- RunRabbitRun.logger.info "[#{@name}] process finished"
55
+ RunRabbitRun.local_logger.info "[#{@name}] process finished"
56
56
  end
57
57
 
58
58
  Process.detach(@pid)
@@ -34,10 +34,10 @@ module RunRabbitRun
34
34
 
35
35
  def send_signal name, pid, signal
36
36
  if running? pid
37
- RunRabbitRun.logger.info "[#{name}] send #{signal_name(signal)} signal to process"
37
+ RunRabbitRun.local_logger.info "[#{name}] send #{signal_name(signal)} signal to process"
38
38
  Process.kill(signal, pid)
39
39
  else
40
- RunRabbitRun.logger.debug "[#{name}] is not running"
40
+ RunRabbitRun.local_logger.debug "[#{name}] is not running"
41
41
  end
42
42
  end
43
43
 
@@ -59,6 +59,10 @@ module RunRabbitRun
59
59
  @exchange ||= channel.direct('')
60
60
  end
61
61
 
62
+ def log_exchange
63
+ @log_exchange = channel.fanout("log")
64
+ end
65
+
62
66
  def stop
63
67
  bunny.stop if @bunny
64
68
 
@@ -1,3 +1,3 @@
1
1
  module RunRabbitRun
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -4,6 +4,7 @@ require 'amqp'
4
4
  require 'bson'
5
5
  require 'json'
6
6
  require 'logger'
7
+ require 'socket'
7
8
 
8
9
  module RunRabbitRun
9
10
  require 'run_rabbit_run/master'
@@ -24,7 +25,11 @@ module RunRabbitRun
24
25
  end
25
26
 
26
27
  def logger
27
- @@logger ||= begin
28
+ @@logger ||= MQLogger.new
29
+ end
30
+
31
+ def local_logger
32
+ @@local_logger ||= begin
28
33
  path = self.config[:log]
29
34
 
30
35
  FileUtils.mkdir_p(File.dirname(path)) unless File.exists?(File.dirname(path))
@@ -40,5 +45,39 @@ module RunRabbitRun
40
45
  logger
41
46
  end
42
47
  end
48
+
49
+ class MQLogger
50
+
51
+ def info(message)
52
+ exchange.publish(_message(message), :routing_key => "info")
53
+ end
54
+
55
+ def error(message)
56
+ exchange.publish(_message(message), :routing_key => "exception")
57
+ end
58
+
59
+ def debug(message)
60
+ exchange.publish(_message(message), :routing_key => "debug")
61
+ end
62
+
63
+ def connection
64
+ @connection ||= AMQP.connect(RunRabbitRun::Config.options[:rabbitmq])
65
+ end
66
+
67
+ def channel
68
+ @channel ||= AMQP::Channel.new(connection, AMQP::Channel.next_channel_id, auto_recovery: true)
69
+ end
70
+
71
+ def exchange
72
+ @exchange ||= channel.topic("log")
73
+ end
74
+
75
+ private
76
+
77
+ def _message(message)
78
+ JSON.generate({message: message, host: Socket.gethostname})
79
+ end
80
+
81
+ end
43
82
  end
44
83
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: run_rabbit_run
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
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-04-30 00:00:00.000000000 Z
12
+ date: 2013-05-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake