pushyd 0.1.1 → 0.2.0
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.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/bin/{pushyd.rb → pushyd} +1 -7
- data/lib/pushyd/constants.rb +10 -0
- data/lib/pushyd/daemon.rb +12 -3
- data/lib/pushyd/endpoint.rb +21 -10
- data/lib/pushyd/proxy.rb +6 -6
- data/lib/pushyd/pushy_logger.rb +61 -0
- data/lib/pushyd/shouter.rb +4 -5
- data/lib/pushyd.rb +1 -0
- data/pushyd.gemspec +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c969ee7254c157dc251ed7e2a8608d35ddef72de
|
4
|
+
data.tar.gz: 746e6b66dcbbecf7c46c11aa89a4e552708d820a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ab2bb5a1eb46ae1b30b29c76c031331dec347bb54ee028d9d27ffa7d0abe4007baa6ff3e3861f4ef4e6c2fdb05aa287c26292739c6331808d5e22bfb5dfc455e
|
7
|
+
data.tar.gz: 0b5b868b6315988e49b41b0e52c7fb593d0d7716c396f1aa65edd72920124bc4fb41f7207c4332f03f084a1dc798d578f0f057fe969e0d70f55674a39ea2998d
|
data/Gemfile.lock
CHANGED
data/bin/{pushyd.rb → pushyd}
RENAMED
@@ -64,13 +64,7 @@ Daemons.run_proc('pushy-daemon', run_options) do
|
|
64
64
|
puts "--- loading code and logger"
|
65
65
|
require_relative "../lib/pushyd"
|
66
66
|
|
67
|
-
# Prepare logger
|
68
|
-
if Config[:log]
|
69
|
-
logger = Logger.new(Config[:log])
|
70
|
-
logger.info('Daemon starting')
|
71
|
-
end
|
72
|
-
|
73
67
|
# Start daemon
|
74
68
|
puts "--- starting"
|
75
|
-
PushyDaemon::Daemon.run
|
69
|
+
PushyDaemon::Daemon.run
|
76
70
|
end
|
data/lib/pushyd/constants.rb
CHANGED
@@ -10,4 +10,14 @@ PROXY_USE_ACK = false
|
|
10
10
|
PROXY_SCOPE = "dev"
|
11
11
|
|
12
12
|
|
13
|
+
# Constants: logger
|
14
|
+
LOG_COL_ID = 6
|
15
|
+
LOG_TRIM_LINE = 200
|
16
|
+
LOG_FORMAT_TIME = "%Y-%m-%d %H:%M:%S"
|
17
|
+
LOG_FORMAT_MESSAGE = "%-6s"
|
18
|
+
LOG_NEWLINE = "\n"
|
19
|
+
LOG_INDENT = "\t"
|
20
|
+
LOG_ROTATION = "daily"
|
21
|
+
|
22
|
+
|
13
23
|
# Constants: shouter
|
data/lib/pushyd/daemon.rb
CHANGED
@@ -1,18 +1,27 @@
|
|
1
1
|
module PushyDaemon
|
2
2
|
class Daemon
|
3
3
|
|
4
|
-
def self.run
|
4
|
+
def self.run
|
5
5
|
# Create a new proxy
|
6
|
-
p = Proxy.new
|
6
|
+
p = Proxy.new
|
7
7
|
|
8
8
|
# Dump config table
|
9
9
|
puts p.table.to_s
|
10
10
|
|
11
11
|
# Create a new shouter
|
12
|
-
s = Shouter.new
|
12
|
+
s = Shouter.new
|
13
13
|
|
14
14
|
# Start infinite loop
|
15
15
|
s.shout
|
16
|
+
|
17
|
+
rescue Errno::EACCES => e
|
18
|
+
#logger.error "ABORT #{e.class}: #{e.message}"
|
19
|
+
abort "ABORT #{e.class}: #{e.message}"
|
20
|
+
|
21
|
+
rescue Exception => e
|
22
|
+
#logger.error "ABORT #{e.class}: #{e.message}"
|
23
|
+
abort "ABORT #{e.class}: #{e.message}"
|
24
|
+
|
16
25
|
end
|
17
26
|
|
18
27
|
end
|
data/lib/pushyd/endpoint.rb
CHANGED
@@ -10,27 +10,33 @@ module PushyDaemon
|
|
10
10
|
|
11
11
|
class Endpoint
|
12
12
|
|
13
|
-
def initialize
|
14
|
-
|
13
|
+
def initialize
|
14
|
+
# Prepare logger (may be NIL > won't output anything)
|
15
|
+
logfile = Config[:log]
|
16
|
+
|
17
|
+
# Create the logger
|
18
|
+
@logger = PushyLogger.new(logfile, LOG_ROTATION)
|
19
|
+
@logger.add Logger::INFO, "starting #{self.class.name.to_s}"
|
15
20
|
end
|
16
21
|
|
17
22
|
protected
|
18
23
|
|
19
|
-
def
|
20
|
-
@logger.
|
21
|
-
raise "ABORT #{self.class}: #{message}"
|
24
|
+
def error message
|
25
|
+
@logger.add Logger::ERROR, "#{self.class}: #{message}"
|
26
|
+
#raise "ABORT #{self.class}: #{message}"
|
22
27
|
end
|
23
28
|
|
24
29
|
def info message
|
25
|
-
@logger.
|
30
|
+
@logger.add Logger::INFO, "#{self.class}: #{message}"
|
26
31
|
end
|
27
32
|
|
28
33
|
def message params = {}
|
29
34
|
# Indenting
|
30
|
-
indent = " " * (params[:way].length)
|
35
|
+
#indent = " " * (params[:way].length)
|
36
|
+
lines = []
|
31
37
|
|
32
38
|
# Header
|
33
|
-
|
39
|
+
message = sprintf(
|
34
40
|
"%3s %-15s %s",
|
35
41
|
params[:way],
|
36
42
|
params[:exchange],
|
@@ -39,17 +45,22 @@ module PushyDaemon
|
|
39
45
|
|
40
46
|
# Attributes
|
41
47
|
if (params[:attrs].is_a? Hash)
|
48
|
+
# lines.merge params[:attrs]
|
42
49
|
params[:attrs].each do |name, value|
|
43
|
-
|
50
|
+
lines << sprintf("%-15s %s", name, value)
|
44
51
|
end
|
45
52
|
end
|
46
53
|
|
47
54
|
# Body (split in lines to log them separately)
|
48
55
|
unless (params[:body].nil? || params[:body].empty?)
|
49
56
|
JSON.pretty_generate(params[:body]).each_line do |line|
|
50
|
-
|
57
|
+
lines << line.rstrip
|
51
58
|
end
|
52
59
|
end
|
60
|
+
|
61
|
+
# Send the info
|
62
|
+
@logger.add Logger::INFO, message, lines
|
63
|
+
# @logger.log_info message, lines
|
53
64
|
end
|
54
65
|
|
55
66
|
# Start connexion to RabbitMQ
|
data/lib/pushyd/proxy.rb
CHANGED
@@ -11,10 +11,10 @@ module PushyDaemon
|
|
11
11
|
|
12
12
|
attr_accessor :table
|
13
13
|
|
14
|
-
def initialize
|
14
|
+
def initialize
|
15
15
|
# Init
|
16
|
+
super
|
16
17
|
@exchanges = {}
|
17
|
-
@logger = logger
|
18
18
|
|
19
19
|
# Init ASCII table
|
20
20
|
@table = Terminal::Table.new
|
@@ -30,7 +30,7 @@ module PushyDaemon
|
|
30
30
|
# Check config
|
31
31
|
config_rules = Config[:rules]
|
32
32
|
unless (config_rules.is_a? Enumerable) && !config_rules.empty?
|
33
|
-
|
33
|
+
error "prepare: empty [rules] section"
|
34
34
|
end
|
35
35
|
info "found rules: #{config_rules.keys.join(', ')}"
|
36
36
|
|
@@ -45,7 +45,7 @@ module PushyDaemon
|
|
45
45
|
info "dumping configuration\n#{@table.to_s}"
|
46
46
|
|
47
47
|
rescue Bunny::TCPConnectionFailedForAllHosts => e
|
48
|
-
|
48
|
+
error "ERROR: cannot connect to RabbitMQ hosts (#{e.inspect})"
|
49
49
|
end
|
50
50
|
|
51
51
|
private
|
@@ -102,7 +102,7 @@ module PushyDaemon
|
|
102
102
|
info "#{id}: #{response.body}"
|
103
103
|
|
104
104
|
rescue Exception => e
|
105
|
-
|
105
|
+
error "propagate: #{e.message}"
|
106
106
|
|
107
107
|
end
|
108
108
|
|
@@ -128,7 +128,7 @@ module PushyDaemon
|
|
128
128
|
|
129
129
|
# Handle body parse errors
|
130
130
|
rescue Encoding::UndefinedConversionError => e
|
131
|
-
|
131
|
+
error "parse: JSON PARSE ERROR: #{e.inspect}"
|
132
132
|
return {}
|
133
133
|
end
|
134
134
|
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require "logger"
|
2
|
+
|
3
|
+
class PushyLogger < Logger
|
4
|
+
|
5
|
+
def initialize logfile, rotation = nil
|
6
|
+
# Call my parent's initializer
|
7
|
+
super
|
8
|
+
|
9
|
+
# And the formatter
|
10
|
+
self.formatter = proc do |severity, datetime, progname, messages|
|
11
|
+
# Build common line prefix
|
12
|
+
prefix = "%s %s\t" % [
|
13
|
+
datetime.strftime(LOG_FORMAT_TIME),
|
14
|
+
severity ]
|
15
|
+
|
16
|
+
# If we have a bunch of lines, prefix them and send them together
|
17
|
+
if messages.is_a? Array
|
18
|
+
messages.map { |line| prefix + line + LOG_NEWLINE}.join
|
19
|
+
else
|
20
|
+
prefix + messages.to_s + LOG_NEWLINE
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def add level, message, lines = {}
|
26
|
+
level ||= Logger::DEBUG
|
27
|
+
|
28
|
+
prefix = " | "
|
29
|
+
|
30
|
+
if lines.is_a? Hash
|
31
|
+
output = build_from_hash prefix, lines
|
32
|
+
elsif lines.is_a? Array
|
33
|
+
output = build_from_array prefix, lines
|
34
|
+
else
|
35
|
+
output = []
|
36
|
+
end
|
37
|
+
|
38
|
+
# Prepend plain message to output
|
39
|
+
output.unshift message.force_encoding(Encoding::UTF_8)
|
40
|
+
|
41
|
+
# Send all this to logger
|
42
|
+
super level, output
|
43
|
+
end
|
44
|
+
|
45
|
+
protected
|
46
|
+
|
47
|
+
def build_from_array prefix, lines
|
48
|
+
lines.map do |value|
|
49
|
+
text = value.to_s[0..LOG_TRIM_LINE]
|
50
|
+
"#{prefix}#{text}"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def build_from_hash prefix, lines
|
55
|
+
lines.map do |name, value|
|
56
|
+
text = value.to_s.strip[0..LOG_TRIM_LINE]
|
57
|
+
"#{prefix}#{name}: #{text}"
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
data/lib/pushyd/shouter.rb
CHANGED
@@ -13,9 +13,9 @@ module PushyDaemon
|
|
13
13
|
|
14
14
|
attr_accessor :table
|
15
15
|
|
16
|
-
def initialize
|
16
|
+
def initialize
|
17
17
|
# Init
|
18
|
-
|
18
|
+
super
|
19
19
|
@keys = []
|
20
20
|
|
21
21
|
# Start connexion to RabbitMQ and create channel
|
@@ -32,7 +32,7 @@ module PushyDaemon
|
|
32
32
|
info "found topic: #{@topic}"
|
33
33
|
info "found keys: #{@keys.join(', ')}"
|
34
34
|
else
|
35
|
-
|
35
|
+
error "prepare: empty [shout] section"
|
36
36
|
end
|
37
37
|
|
38
38
|
# Create exchange
|
@@ -44,7 +44,7 @@ module PushyDaemon
|
|
44
44
|
# end
|
45
45
|
|
46
46
|
rescue Bunny::TCPConnectionFailedForAllHosts => e
|
47
|
-
|
47
|
+
error "ERROR: cannot connect to RabbitMQ hosts (#{e.inspect})"
|
48
48
|
end
|
49
49
|
|
50
50
|
def shout
|
@@ -66,7 +66,6 @@ module PushyDaemon
|
|
66
66
|
|
67
67
|
rescue Interrupt => e
|
68
68
|
@channel.close
|
69
|
-
# conn.close
|
70
69
|
raise PushyDaemon::ShouterInterrupted, "#{e.class} (#{e.inspect})"
|
71
70
|
end
|
72
71
|
|
data/lib/pushyd.rb
CHANGED
data/pushyd.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pushyd
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bruno MEDICI
|
@@ -167,7 +167,7 @@ dependencies:
|
|
167
167
|
description: "(description to be written)"
|
168
168
|
email: pushyd@bmconseil.com
|
169
169
|
executables:
|
170
|
-
- pushyd
|
170
|
+
- pushyd
|
171
171
|
extensions: []
|
172
172
|
extra_rdoc_files: []
|
173
173
|
files:
|
@@ -176,7 +176,7 @@ files:
|
|
176
176
|
- Gemfile.lock
|
177
177
|
- README.md
|
178
178
|
- Rakefile
|
179
|
-
- bin/pushyd
|
179
|
+
- bin/pushyd
|
180
180
|
- defaults.yml
|
181
181
|
- lib/pushyd.rb
|
182
182
|
- lib/pushyd/config.rb
|
@@ -184,6 +184,7 @@ files:
|
|
184
184
|
- lib/pushyd/daemon.rb
|
185
185
|
- lib/pushyd/endpoint.rb
|
186
186
|
- lib/pushyd/proxy.rb
|
187
|
+
- lib/pushyd/pushy_logger.rb
|
187
188
|
- lib/pushyd/shouter.rb
|
188
189
|
- pushyd.gemspec
|
189
190
|
homepage: http://github.com/bmedici/pushyd
|