pushyd 0.8.2 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/defaults.yml +9 -9
- data/lib/pushyd/constants.rb +3 -0
- data/lib/pushyd/endpoint.rb +17 -2
- data/lib/pushyd/proxy.rb +23 -4
- data/lib/pushyd/shouter.rb +23 -10
- data/pushyd.gemspec +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8eb02de265011f5fec1f4d59bc19ea7c74e04cf4
|
4
|
+
data.tar.gz: adeae96fac08c64d054849f8a5ecb740f42310e9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7233e7947eaaaf3111cbfea945a92b9cedcaa11baeb64b95646944ee148a96ed2c1ceba16e8f675721f4c584986493aff1f9d7a20a7fa8e127e0d8fab413ba38
|
7
|
+
data.tar.gz: 7b19b454c1e3afd721cbd78a99c4752ec70daec74413c558c31533de8677ce054c21a38cf314e597ad7819e3bc8aa1291fa542081191d023a62af017ffb98f06
|
data/Gemfile.lock
CHANGED
data/defaults.yml
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# common defaults
|
2
|
-
|
2
|
+
broker: amqp://guest:guest@localhost:5672/%2F
|
3
3
|
logs:
|
4
4
|
path: '/tmp/'
|
5
5
|
file: pushyd.log
|
@@ -9,14 +9,14 @@ logs:
|
|
9
9
|
shout:
|
10
10
|
topic: pushyd
|
11
11
|
period: 10
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
12
|
+
keys:
|
13
|
+
- tic
|
14
|
+
- tac
|
15
|
+
- toe
|
16
|
+
- created
|
17
|
+
- updated
|
18
|
+
- deleted
|
19
|
+
- crunched
|
20
20
|
|
21
21
|
# newrelic:
|
22
22
|
# licence: ""
|
data/lib/pushyd/constants.rb
CHANGED
data/lib/pushyd/endpoint.rb
CHANGED
@@ -74,7 +74,12 @@ module PushyDaemon
|
|
74
74
|
# Start connexion to RabbitMQ
|
75
75
|
def connect_channel busconf
|
76
76
|
fail PushyDaemon::EndpointConnexionContext, "invalid bus host/port" unless busconf
|
77
|
-
info "connecting to
|
77
|
+
info "connecting to bus", {
|
78
|
+
broker: busconf,
|
79
|
+
recover: AMQP_RECOVERY_INTERVAL,
|
80
|
+
heartbeat: AMQP_HEARTBEAT_INTERVAL,
|
81
|
+
prefetch: AMQP_PREFETCH
|
82
|
+
}
|
78
83
|
conn = Bunny.new busconf.to_s,
|
79
84
|
logger: @logger,
|
80
85
|
# heartbeat: :server,
|
@@ -83,7 +88,6 @@ module PushyDaemon
|
|
83
88
|
heartbeat_interval: AMQP_HEARTBEAT_INTERVAL
|
84
89
|
conn.start
|
85
90
|
|
86
|
-
|
87
91
|
# Create channel, prefetch only one message at a time
|
88
92
|
channel = conn.create_channel
|
89
93
|
channel.prefetch(AMQP_PREFETCH)
|
@@ -151,6 +155,17 @@ module PushyDaemon
|
|
151
155
|
rand(36**len).to_s(36)
|
152
156
|
end
|
153
157
|
|
158
|
+
def format_bytes number, unit="", decimals = 0
|
159
|
+
return "Ø" if number.nil? || number.to_f.zero?
|
160
|
+
|
161
|
+
units = ["", "k", "M", "G", "T", "P" ]
|
162
|
+
index = ( Math.log(number) / Math.log(2) ).to_i / 10
|
163
|
+
converted = number.to_f / (1024 ** index)
|
164
|
+
|
165
|
+
truncated = converted.round(decimals)
|
166
|
+
return "#{truncated} #{units[index]}#{unit}"
|
167
|
+
end
|
168
|
+
|
154
169
|
private
|
155
170
|
|
156
171
|
end
|
data/lib/pushyd/proxy.rb
CHANGED
@@ -20,7 +20,7 @@ module PushyDaemon
|
|
20
20
|
@table.align_column(5, :right)
|
21
21
|
|
22
22
|
# Start connexion to RabbitMQ and create channel
|
23
|
-
@channel = connect_channel Conf
|
23
|
+
@channel = connect_channel Conf[:broker]
|
24
24
|
log_info "channel connected"
|
25
25
|
|
26
26
|
# Check config
|
@@ -45,6 +45,19 @@ module PushyDaemon
|
|
45
45
|
|
46
46
|
private
|
47
47
|
|
48
|
+
def extract_delay msg_headers
|
49
|
+
return unless msg_headers['sent_at']
|
50
|
+
|
51
|
+
# Extract sent_at header
|
52
|
+
sent_at = Time.iso8601(msg_headers['sent_at'])
|
53
|
+
# log_info "sent_at : #{sent_at.to_f}"
|
54
|
+
# log_info "timenow : #{Time.now.to_f}"
|
55
|
+
|
56
|
+
# Compute delay
|
57
|
+
return ((Time.now - sent_at)*1000).round(2)
|
58
|
+
end
|
59
|
+
|
60
|
+
|
48
61
|
# Handle the reception of a message on a queue
|
49
62
|
def handle_message rule, delivery_info, metadata, payload
|
50
63
|
# Prepare data
|
@@ -53,14 +66,20 @@ module PushyDaemon
|
|
53
66
|
msg_rkey = delivery_info.routing_key.force_encoding('UTF-8')
|
54
67
|
msg_headers = metadata.headers || {}
|
55
68
|
|
56
|
-
#
|
57
|
-
|
69
|
+
# Compute delay and size
|
70
|
+
delay = extract_delay(msg_headers)
|
71
|
+
size = format_bytes(payload.bytesize, "B")
|
72
|
+
|
73
|
+
# Extract payload
|
74
|
+
data = parse payload, metadata.content_type
|
58
75
|
|
59
76
|
# Announce match
|
60
77
|
log_message MSG_RECV, msg_exchange, msg_rkey, data, {
|
61
|
-
'rule' => rule_name,
|
78
|
+
'matched rule' => rule_name,
|
62
79
|
'app-id' => metadata.app_id,
|
63
80
|
'content-type' => metadata.content_type,
|
81
|
+
'delay (ms)' => delay,
|
82
|
+
'body size' => size,
|
64
83
|
}
|
65
84
|
|
66
85
|
# Build notification payload
|
data/lib/pushyd/shouter.rb
CHANGED
@@ -27,7 +27,7 @@ module PushyDaemon
|
|
27
27
|
@period = config_shout[:period] || 0
|
28
28
|
|
29
29
|
# Start connexion to RabbitMQ and create channel
|
30
|
-
@channel = connect_channel Conf
|
30
|
+
@channel = connect_channel Conf[:broker]
|
31
31
|
log_info "channel connected"
|
32
32
|
|
33
33
|
# Create exchange
|
@@ -44,9 +44,21 @@ module PushyDaemon
|
|
44
44
|
|
45
45
|
# Prepare exchange
|
46
46
|
loop do
|
47
|
+
# Generate key and fake id
|
48
|
+
if @keys.is_a?(Array) && @keys.any?
|
49
|
+
random_key = @keys.sample
|
50
|
+
else
|
51
|
+
random_key = "random"
|
52
|
+
end
|
53
|
+
# random_key = @keys.class
|
47
54
|
random_string = SecureRandom.hex
|
48
|
-
|
49
|
-
|
55
|
+
|
56
|
+
# Generate payload
|
57
|
+
#payload = {time: Time.now.to_f, host: Conf.host}
|
58
|
+
payload = nil
|
59
|
+
|
60
|
+
# Shout it !
|
61
|
+
channel_shout [:ping, random_key, random_string], payload
|
50
62
|
sleep @period
|
51
63
|
end
|
52
64
|
rescue AMQ::Protocol::EmptyResponseError => e
|
@@ -65,19 +77,20 @@ module PushyDaemon
|
|
65
77
|
private
|
66
78
|
|
67
79
|
def channel_shout keys, body = {}
|
68
|
-
# Prepare headers
|
69
|
-
headers = {
|
70
|
-
sent_at: DateTime.now.iso8601,
|
71
|
-
sent_by: Conf.app_name,
|
72
|
-
}
|
73
|
-
|
74
80
|
# Prepare exchange_name and routing_key
|
75
81
|
exchange_name = @exchange.name
|
76
|
-
|
82
|
+
keys.unshift(exchange_name)
|
83
|
+
routing_key = keys.join('.')
|
77
84
|
|
78
85
|
# Announce shout
|
79
86
|
log_message MSG_SEND, exchange_name, routing_key, body
|
80
87
|
|
88
|
+
# Prepare headers
|
89
|
+
headers = {
|
90
|
+
sent_at: DateTime.now.iso8601(SHOUTER_SENTAT_DECIMALS),
|
91
|
+
sent_by: Conf.app_name,
|
92
|
+
}
|
93
|
+
|
81
94
|
# Publish
|
82
95
|
@exchange.publish(body.to_json,
|
83
96
|
routing_key: routing_key,
|
data/pushyd.gemspec
CHANGED