pushyd 0.25.0 → 0.26.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1bf480c7c62d3a53870416ec77b427dd66dd0576
4
- data.tar.gz: 1de20b6c29e3aca9aef05a616bc28ae27f4a42d9
3
+ metadata.gz: 40d8b0ca991da2673c872f8dd20865c9c8423a1f
4
+ data.tar.gz: fd793ad3c7c38d72eeca44fd7aa2a09ad965fc8b
5
5
  SHA512:
6
- metadata.gz: c3d64b444baa8cabd798e29933e214f3731a46439583014e35ded348d6e9f75a4132eb9d446b92aee14dcf310e8b1746f3dc4e2758374924fd6c11f0c246bfb2
7
- data.tar.gz: d2e5425547396b6e048d9c264a13ed63d00ac965d92b71f6cdd77a591dce731fab720d6eb8d1de9e957c1d9888aab74dd7cd81a8ca9f9fe3d93a9fe8ce1a4af4
6
+ metadata.gz: 490dd865467775ff6f9b3b8a588636c3f7192cb135305583c05cb24e0f6185051294dcf61a475c148dc39f64d3842b37a810c12c57090297c00f4bd94ea4a711
7
+ data.tar.gz: db8fb4341181f1fd9690df6d7da85a2567a3d1a280c25e7ae20f294430bc5feea549b7c728ce8a8bedaaa50691954118b841b3ece08434f63dc0a89ce5cc483b
data/defaults.yml CHANGED
@@ -12,7 +12,7 @@ logs:
12
12
 
13
13
  shout:
14
14
  topic: pushyd
15
- period: 10
15
+ period: 10.0
16
16
  keys:
17
17
  - tic
18
18
  - tac
@@ -5,28 +5,21 @@ module PushyDaemon
5
5
  # class ShouterInterrupted < StandardError; end
6
6
  class ConsumerError < StandardError; end
7
7
  class ConsumerRuleMissing < StandardError; end
8
+ class ConsumerSubscribeError < StandardError; end
8
9
 
9
10
  class Consumer < BmcDaemonLib::MqConsumer
10
11
  #include ::NewRelic::Agent::Instrumentation::ControllerInstrumentation
11
12
  include Shared::HmacSignature
12
- attr_accessor :logger
13
13
 
14
- def initialize(conn, rule_name, rule)
14
+ def initialize(channel, rule_name, rule)
15
+ # Init MqConsumer
16
+ log_pipe :consumer
17
+ super
18
+
15
19
  # Init
16
20
  @queue = nil
17
- @conn = conn
18
21
  @rule = rule
19
22
  @rule_name = rule_name
20
-
21
- # Prepare logger
22
- log_pipe :consumer
23
-
24
- # Create channel, prefetch only one message at a time
25
- @channel = @conn.create_channel
26
- @channel.prefetch(AMQP_PREFETCH)
27
-
28
- # OK
29
- log_info "Consumer initialized"
30
23
  end
31
24
 
32
25
  protected
@@ -135,7 +128,7 @@ module PushyDaemon
135
128
 
136
129
  # rescue StandardError => ex
137
130
  # log_debug "channel_ackit[#{@channel.id}.#{tag}]: exception: #{ex.inspect}"
138
- # # fail PushyDaemon::EndpointSubscribeError, "unhandled (#{e.inspect})"
131
+ # # fail PushyDaemon::ConsumerSubscribeError, "unhandled (#{e.inspect})"
139
132
 
140
133
  # else
141
134
  # log_debug "channel_ackit[#{@channel.id}.#{tag}]: done"
@@ -144,6 +137,5 @@ module PushyDaemon
144
137
  # NewRelic instrumentation
145
138
  #add_transaction_tracer :receive, category: :task
146
139
  #add_transaction_tracer :propagate, category: :task
147
-
148
140
  end
149
141
  end
data/lib/pushyd/proxy.rb CHANGED
@@ -4,6 +4,10 @@ require 'rest_client'
4
4
  require 'terminal-table'
5
5
 
6
6
  module PushyDaemon
7
+ class EndpointConnexionContext < StandardError; end
8
+ class ProxyConnectionError < StandardError; end
9
+ class ProxyConsumerError < StandardError; end
10
+
7
11
  class Proxy < BmcDaemonLib::MqEndpoint
8
12
  #include ::NewRelic::Agent::Instrumentation::ControllerInstrumentation
9
13
 
@@ -25,11 +29,10 @@ module PushyDaemon
25
29
  @logger = BmcDaemonLib::LoggerPool.instance.get
26
30
 
27
31
  # Start connexion to RabbitMQ
28
- @conn = connect_to BmcDaemonLib::Conf[:broker]
29
- log_info "Proxy connected"
32
+ connect_to BmcDaemonLib::Conf[:broker]
30
33
 
31
34
  # Create a new shouter
32
- @shouter = create_shouter
35
+ create_shouter
33
36
 
34
37
  # Check config and subscribe rules
35
38
  create_consumers
@@ -42,10 +45,10 @@ module PushyDaemon
42
45
  @shouter.start_loop
43
46
 
44
47
  rescue BmcDaemonLib::MqConsumerException => e
45
- log_error "Proxy consumer: #{e.message}"
48
+ log_error "Proxy exception: #{e.message}"
46
49
  abort "EXITING #{e.class}: #{e.message}"
47
50
 
48
- rescue ShouterInterrupted, EndpointConnectionError, Errno::EACCES => e
51
+ rescue ShouterInterrupted, ProxyConnectionError, Errno::EACCES => e
49
52
  log_error "Proxy error: #{e.message}"
50
53
  abort "EXITING #{e.class}: #{e.message}"
51
54
 
@@ -62,15 +65,14 @@ module PushyDaemon
62
65
  {
63
66
  me: :proxy
64
67
  }
65
-
66
68
  end
67
69
 
68
70
  def create_shouter
69
- # Get config
70
- config_shouter = BmcDaemonLib::Conf[:shout]
71
+ # Create my channel
72
+ channel = @conn.create_channel
71
73
 
72
74
  # Create the shouter
73
- Shouter.new(@conn, config_shouter)
75
+ @shouter = Shouter.new(channel, BmcDaemonLib::Conf[:shout])
74
76
  end
75
77
 
76
78
  def create_consumers
@@ -104,13 +106,14 @@ module PushyDaemon
104
106
  end
105
107
 
106
108
  # Check we have a topic and at least one routing key
107
- fail PushyDaemon::EndpointSubscribeContext, "rule [#{rule_name}] lacking topic" unless rule_topic
108
- fail PushyDaemon::EndpointSubscribeContext, "rule [#{rule_name}] lacking keys" if rule_keys.empty?
109
+ fail BmcDaemonLib::ProxyConsumerError, "rule [#{rule_name}] lacking topic" unless rule_topic
110
+ fail BmcDaemonLib::ProxyConsumerError, "rule [#{rule_name}] lacking keys" if rule_keys.empty?
109
111
 
110
- # Build a new consumer
111
- consumer = Consumer.new(@conn, rule_name, rule)
112
+ # Build a new consumer on its own channel
113
+ channel = @conn.create_channel
114
+ consumer = Consumer.new(channel, rule_name, rule)
112
115
 
113
- # Subscribe to my own queue
116
+ # Subscribe to its own queue
114
117
  consumer.subscribe_to_queue rule_queue, "rule:#{rule_name}"
115
118
 
116
119
  # Bind each key to exchange
@@ -140,5 +143,33 @@ module PushyDaemon
140
143
  log_error "consumer_cancelled remotely: #{all.inspect}"
141
144
  end
142
145
 
146
+ # Start connexion to RabbitMQ
147
+ def connect_to busconf
148
+ fail ProxyConnectionError, "connect_to/busconf" unless busconf
149
+ log_info "connect_to: connecting to broker", {
150
+ broker: busconf,
151
+ recover: AMQP_RECOVERY_INTERVAL,
152
+ heartbeat: AMQP_HEARTBEAT_INTERVAL,
153
+ prefetch: AMQP_PREFETCH
154
+ }
155
+ @conn = Bunny.new busconf.to_s,
156
+ logger: @logger,
157
+ # heartbeat: :server,
158
+ automatically_recover: true,
159
+ network_recovery_interval: AMQP_RECOVERY_INTERVAL,
160
+ heartbeat_interval: AMQP_HEARTBEAT_INTERVAL,
161
+ read_write_timeout: AMQP_HEARTBEAT_INTERVAL*2
162
+
163
+ # Start the connection
164
+ @conn.start
165
+
166
+ rescue Bunny::TCPConnectionFailedForAllHosts, Bunny::AuthenticationFailureError, AMQ::Protocol::EmptyResponseError => e
167
+ fail ProxyConnectionError, "error connecting (#{e.class})"
168
+ rescue StandardError => e
169
+ fail ProxyConnectionError, "unknow (#{e.inspect})"
170
+ else
171
+ #return conn
172
+ end
173
+
143
174
  end
144
175
  end
@@ -7,20 +7,19 @@ module PushyDaemon
7
7
 
8
8
  class Shouter < BmcDaemonLib::MqEndpoint
9
9
  include ::NewRelic::Agent::Instrumentation::ControllerInstrumentation
10
- include BmcDaemonLib::LoggerHelper
10
+ include LoggerHelper
11
+ attr_accessor :logger
11
12
 
12
13
  # Class options
13
14
  attr_accessor :table
14
- attr_accessor :logger
15
15
 
16
- def initialize(conn, config_shout)
16
+ def initialize(channel, config_shout)
17
+ # Init MqConsumer
18
+ log_pipe :shouter
19
+ super
20
+
17
21
  # Init
18
22
  @shouter_keys = []
19
- @channel = nil
20
- @exchange = nil
21
-
22
- # Prepare logger
23
- log_pipe :shouter
24
23
 
25
24
  # Check config
26
25
  unless config_shout && config_shout.any? && config_shout.is_a?(Enumerable)
@@ -31,20 +30,22 @@ module PushyDaemon
31
30
  # Extract information
32
31
  @shouter_keys = config_shout[:keys] if config_shout[:keys].is_a? Array
33
32
  @shouter_topic = config_shout[:topic]
34
- @shouter_period = config_shout[:period].to_i
33
+ @shouter_period = config_shout[:period].to_f
35
34
  @shouter_period = 1 unless (@shouter_period > 0)
36
35
 
37
36
  fail PushyDaemon::EndpointTopicContext unless @shouter_topic
38
37
 
39
- # Create channel and exchange
40
- @channel = conn.create_channel
38
+ # Create exchange
41
39
  @exchange = @channel.topic(@shouter_topic, durable: true, persistent: true)
40
+ #log_info "channel[#{@channel.id}] created, prefetch[#{AMQP_PREFETCH}]"
42
41
 
43
42
  # Start working, now
44
- log_info "Shouter initialized, starting loop now", { topic: @shouter_topic, period: @shouter_period, keys: @shouter_keys }
43
+ log_info "shouter initialized"
45
44
  end
46
45
 
47
46
  def start_loop
47
+ log_info "shouter start_loop", { topic: @shouter_topic, period: @shouter_period, keys: @shouter_keys }
48
+
48
49
  # Prepare exchange
49
50
  loop do
50
51
  # Generate payload
data/pushyd.gemspec CHANGED
@@ -1,7 +1,7 @@
1
1
  # coding: utf-8
2
2
  Gem::Specification.new do |spec|
3
3
  # Project version
4
- spec.version = "0.25.0"
4
+ spec.version = "0.26.0"
5
5
 
6
6
  # Project description
7
7
  spec.name = "pushyd"
@@ -28,7 +28,8 @@ Gem::Specification.new do |spec|
28
28
  # spec.add_development_dependency "pry"
29
29
 
30
30
  # Runtime dependencies
31
- spec.add_runtime_dependency "bmc-daemon-lib", "= 0.9.2"
31
+ # spec.add_runtime_dependency "bmc-daemon-lib"
32
+ spec.add_runtime_dependency "bmc-daemon-lib", "= 0.10.0"
32
33
  spec.add_runtime_dependency "daemons"
33
34
  spec.add_runtime_dependency "json"
34
35
  spec.add_runtime_dependency "bunny", "~> 2.3"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pushyd
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.25.0
4
+ version: 0.26.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bruno MEDICI
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-21 00:00:00.000000000 Z
11
+ date: 2017-04-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -86,14 +86,14 @@ dependencies:
86
86
  requirements:
87
87
  - - '='
88
88
  - !ruby/object:Gem::Version
89
- version: 0.9.2
89
+ version: 0.10.0
90
90
  type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - '='
95
95
  - !ruby/object:Gem::Version
96
- version: 0.9.2
96
+ version: 0.10.0
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: daemons
99
99
  requirement: !ruby/object:Gem::Requirement