boutons 0.4.11 → 0.5.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: 4bf32c460f54bb51b8e81084f6c6dce52a522fc1
4
- data.tar.gz: 2621e3b1a71ede022855c6a2129259134c363822
3
+ metadata.gz: d6dad245837beb250fe94eb0ec089bff8dbb76d6
4
+ data.tar.gz: e32d5ab3f794eb32902476781bfa134d44c997c7
5
5
  SHA512:
6
- metadata.gz: eef7da345812ca05e3f565fd03ddab4733cc91eff25cdd385ff665a2df723f0e813906d47f3c2d7a912cc4ed18efa49d95018c631c277d5376ec489d62ac141b
7
- data.tar.gz: 0829fff8c6a2f847e1dc407f6d6bbe362ad8ca498c4bdb2a9dd8866f3265a8a255c02469b44d86580419536e476b89556c8e72b02c6e9418f13194188f444d01
6
+ metadata.gz: 5f2ccb79ab61da50579d5155cc9489253e1cb6ad50999b5ae83c83360f1769bc272d0f0a65082a27984a5931376ff459ca6b9e0098809fa7ca12ea97d9331279
7
+ data.tar.gz: fc863697467cbd46153ffae597898539d2523af97a1a132c698ab7423865f23e39942830a29205b58a33f9ba4764aff5a6ae9bf0b171b23e94eec310fa932075
@@ -10,6 +10,7 @@ require "boutons/synapse"
10
10
  require "synapse/logging/interchangeable"
11
11
  require "boutons/uri"
12
12
  require "boutons/resource"
13
+ require "boutons/event_sniffer"
13
14
 
14
15
  module Boutons
15
16
  class UnknownSynapse < Exception; end
@@ -36,6 +37,19 @@ module Boutons
36
37
  params[:name] = service.to_sym
37
38
  add Synapse::Easy::Service.new params
38
39
  end
40
+ def notify event, callback
41
+ @callbacks ||= {}
42
+ @callbacks[event] ||= []
43
+ @callbacks[event] << callback
44
+ end
45
+ def emit event
46
+ @callbacks ||= {}
47
+ @callbacks[event] ||= []
48
+ return if @callbacks[event].empty?
49
+ @callbacks[event].each do |callback|
50
+ callback.call
51
+ end
52
+ end
39
53
  def remove name
40
54
  services[mapping[name]] = nil
41
55
  start
@@ -73,6 +87,9 @@ module Boutons
73
87
  Boutons::Config.services.keys.map{|k|k.to_s} rescue []
74
88
  end
75
89
  private
90
+ def event_dispatcher target=nil
91
+ @dispatcher ||= EventSniffer.new target
92
+ end
76
93
  def mapping
77
94
  @@mapping ||= {}
78
95
  end
@@ -91,7 +108,9 @@ module Boutons
91
108
  def start
92
109
  return if @started
93
110
  services.map{|n,s|s.active=true}
94
- haproxy.inform synapse
111
+ event_dispatcher synapse
112
+ event_dispatcher.add_callback -> {self.emit(:restart)}
113
+ haproxy.inform event_dispatcher
95
114
  at_exit do
96
115
  pf = haproxy.pid_file_path
97
116
  cf = haproxy.config_file_path
@@ -103,7 +122,7 @@ module Boutons
103
122
  File.unlink(cf)
104
123
  logger.debug "Boutons shut down"
105
124
  end
106
- services.inform synapse
125
+ services.inform event_dispatcher
107
126
  synapse.services = services
108
127
  @@synapse_thread = Thread.new do
109
128
  synapse.run
@@ -0,0 +1,15 @@
1
+ module Boutons
2
+ class EventSniffer
3
+ def initialize target
4
+ @target = target
5
+ end
6
+ def add_callback callback
7
+ @callbacks ||= []
8
+ @callbacks << callback
9
+ end
10
+ def reconfigure!
11
+ @target.reconfigure!
12
+ @callbacks.map{|callback| callback.call}
13
+ end
14
+ end
15
+ end
@@ -1,3 +1,3 @@
1
1
  module Boutons
2
- VERSION = "0.4.11"
2
+ VERSION = "0.5.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: boutons
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.11
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mathias Kaufmann
@@ -170,6 +170,7 @@ files:
170
170
  - boutons.gemspec
171
171
  - lib/boutons.rb
172
172
  - lib/boutons/config.rb
173
+ - lib/boutons/event_sniffer.rb
173
174
  - lib/boutons/resource.rb
174
175
  - lib/boutons/synapse.rb
175
176
  - lib/boutons/uri.rb