ampel_extase 0.3.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: eca730e291f909a887fece16583fd85b7d64a190
4
- data.tar.gz: 85b253dc3cfd5e6057870f37d2f2a78df014b907
3
+ metadata.gz: ae6a5d724b7c06425fca0953f0e8035cd802f492
4
+ data.tar.gz: c8b9a89b451637c118264ed8988e5302178d261b
5
5
  SHA512:
6
- metadata.gz: 2627d096c3a710912e73f3cad0d8451b0b6d204afe75ee3df945db721928a34c81292cf08b18ae62c77a5f2401490166bf1ee3c6df0baa05a0154dac85204a36
7
- data.tar.gz: eed09f266ea160de81ed0ad1825b1e067d3dd63b1f053516b6175ff0895923c3e4e8d80a32c38a9d687120972a733a07504db92ab48d7161ed17217ee04747a1
6
+ metadata.gz: 85e5bc084b1e0ba6bcaf5293c77b854bbd557c444f6e3e55a4b642395902f689abadf60979f0740cbcb88c7842b82e0121391f280cd8798109f66f41b21ae5df
7
+ data.tar.gz: c97d946b4225c5a50392d6dc8a7739b5da698c68c8e9d11ffabc3ec2d6d6abed207a0b50a32b7d6de2f6273bb05fad513382e89f267f5a86d77cf3161321428a
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.1
1
+ 0.4.0
@@ -1,23 +1,23 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: ampel_extase 0.3.1 ruby lib
2
+ # stub: ampel_extase 0.4.0 ruby lib
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "ampel_extase"
6
- s.version = "0.3.1"
6
+ s.version = "0.4.0"
7
7
 
8
8
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
9
9
  s.require_paths = ["lib"]
10
10
  s.authors = ["Florian Frank"]
11
- s.date = "2015-08-25"
11
+ s.date = "2015-08-26"
12
12
  s.description = "Library to control the build traffic light. Yes, we can\u{2026}"
13
13
  s.email = "flori@ping.de"
14
14
  s.executables = ["ampel_control"]
15
- s.extra_rdoc_files = ["README.md", "lib/ampel_extase.rb", "lib/ampel_extase/build_state.rb", "lib/ampel_extase/controller.rb", "lib/ampel_extase/jenkins_client.rb", "lib/ampel_extase/jenkins_state_observer.rb", "lib/ampel_extase/light_switcher.rb", "lib/ampel_extase/version.rb"]
16
- s.files = [".gitignore", ".utilsrc", "Gemfile", "README.md", "Rakefile", "VERSION", "ampel_extase.gemspec", "bin/ampel_control", "lib/ampel_extase.rb", "lib/ampel_extase/build_state.rb", "lib/ampel_extase/controller.rb", "lib/ampel_extase/jenkins_client.rb", "lib/ampel_extase/jenkins_state_observer.rb", "lib/ampel_extase/light_switcher.rb", "lib/ampel_extase/version.rb", "spec/ampel_extase/build_state_spec.rb", "spec/ampel_extase/controller_spec.rb", "spec/ampel_extase/jekins_state_observer_spec.rb", "spec/ampel_extase/jenkins_client_spec.rb", "spec/ampel_extase/light_switcher_spec.rb", "spec/spec_helper.rb"]
15
+ s.extra_rdoc_files = ["README.md", "lib/ampel_extase.rb", "lib/ampel_extase/build_state.rb", "lib/ampel_extase/controller.rb", "lib/ampel_extase/jenkins_client.rb", "lib/ampel_extase/jenkins_multi_state_observer.rb", "lib/ampel_extase/jenkins_state_observer.rb", "lib/ampel_extase/light_switcher.rb", "lib/ampel_extase/version.rb"]
16
+ s.files = [".gitignore", ".utilsrc", "Gemfile", "README.md", "Rakefile", "VERSION", "ampel_extase.gemspec", "bin/ampel_control", "lib/ampel_extase.rb", "lib/ampel_extase/build_state.rb", "lib/ampel_extase/controller.rb", "lib/ampel_extase/jenkins_client.rb", "lib/ampel_extase/jenkins_multi_state_observer.rb", "lib/ampel_extase/jenkins_state_observer.rb", "lib/ampel_extase/light_switcher.rb", "lib/ampel_extase/version.rb", "spec/ampel_extase/build_state_spec.rb", "spec/ampel_extase/controller_spec.rb", "spec/ampel_extase/jekins_state_observer_spec.rb", "spec/ampel_extase/jenkins_client_spec.rb", "spec/ampel_extase/light_switcher_spec.rb", "spec/spec_helper.rb"]
17
17
  s.homepage = "http://github.com/flori/ampel_extase"
18
18
  s.licenses = ["GPL-2"]
19
19
  s.rdoc_options = ["--title", "AmpelExtase - Library to control the build traffic light", "--main", "README.md"]
20
- s.rubygems_version = "2.4.5.1"
20
+ s.rubygems_version = "2.4.8"
21
21
  s.summary = "Library to control the build traffic light"
22
22
  s.test_files = ["spec/ampel_extase/build_state_spec.rb", "spec/ampel_extase/controller_spec.rb", "spec/ampel_extase/jekins_state_observer_spec.rb", "spec/ampel_extase/jenkins_client_spec.rb", "spec/ampel_extase/light_switcher_spec.rb", "spec/spec_helper.rb"]
23
23
 
@@ -2,8 +2,11 @@
2
2
 
3
3
  require 'ampel_extase'
4
4
 
5
- serial = ENV['SERIAL'].full? or
6
- fail 'need env var SERIAL for path to serial port'
5
+ serial =
6
+ unless ENV['DEMO']
7
+ serial = ENV['SERIAL'].full? or
8
+ fail 'need env var SERIAL for path to serial port'
9
+ end
7
10
  jenkins_url = ENV['JENKINS_URL'].full? or
8
11
  fail 'need env var JENKINS_URL of the form http://test2.local:8080/job/foo'
9
12
  warning_jenkins_url = ENV['WARNING_JENKINS_URL'].full?
@@ -63,6 +63,7 @@ class AmpelExtase::Controller
63
63
  @warning_jenkins.on_state_change do |state|
64
64
  perform_warning state
65
65
  end
66
+ expire_warning
66
67
  end
67
68
 
68
69
  def perform_lights_switch(state)
@@ -99,6 +100,13 @@ class AmpelExtase::Controller
99
100
  end
100
101
  end
101
102
 
103
+ def expire_warning
104
+ if Time.now > @warning_jenkins.state_changed_at + 6 * @sleep
105
+ @lights.aux.off
106
+ puts info('WARNING EXPIRED')
107
+ end
108
+ end
109
+
102
110
  def success(message)
103
111
  green message
104
112
  end
@@ -111,6 +119,9 @@ class AmpelExtase::Controller
111
119
  green on_red message
112
120
  end
113
121
 
122
+ def info(message)
123
+ yellow message
124
+ end
114
125
  def switch_all_lights_off
115
126
  @lights.each(&:off)
116
127
  end
@@ -0,0 +1,21 @@
1
+ require 'ampel_extase/jenkins_state_observer'
2
+
3
+ class AmpelExtase::JenkinsMultiStateObserver
4
+ def self.for_urls(*jenkins_urls)
5
+ new jenkins_urls.map { |jenkins_url| AmpelExtase::JenkinsStateObserver.new(jenkins_url) }
6
+ end
7
+
8
+ def initialize(observers)
9
+ @observers = observers
10
+ end
11
+
12
+ def check
13
+ @observers.each(&:check)
14
+ end
15
+
16
+ def on_state_change(&block)
17
+ @observers.each do |o|
18
+ o.on_state_change(&block)
19
+ end
20
+ end
21
+ end
@@ -13,13 +13,14 @@ class AmpelExtase::JenkinsStateObserver
13
13
 
14
14
  def initialize(jenkins)
15
15
  @jenkins = jenkins
16
- @build_state = AmpelExtase::BuildState.for
16
+ set_state AmpelExtase::BuildState.for
17
17
  check
18
18
  end
19
19
 
20
20
  def check
21
21
  puts "checking jenkins configuration for #{@jenkins.url.to_s.inspect}"
22
22
  @jenkins.fetch and puts "OK"
23
+ self
23
24
  end
24
25
 
25
26
  def last_result
@@ -34,15 +35,25 @@ class AmpelExtase::JenkinsStateObserver
34
35
  new_state != @build_state
35
36
  end
36
37
 
38
+ def set_state(state)
39
+ @build_state = state
40
+ @state_changed_at = Time.now
41
+ self
42
+ end
43
+
44
+ attr_reader :state_changed_at
45
+
37
46
  def on_state_change
38
47
  new_state = AmpelExtase::BuildState.for [ last_result, building? ]
39
48
  if state_changed?(new_state)
40
49
  puts "state changed from #@build_state to #{new_state} => taking action"
41
- yield new_state
50
+ begin
51
+ yield new_state
52
+ ensure
53
+ set_state new_state
54
+ end
42
55
  else
43
56
  puts "state did not change, is still #@build_state => do nothing"
44
57
  end
45
- ensure
46
- @build_state = new_state
47
58
  end
48
59
  end
@@ -1,6 +1,6 @@
1
1
  module AmpelExtase
2
2
  # AmpelExtase version
3
- VERSION = '0.3.1'
3
+ VERSION = '0.4.0'
4
4
  VERSION_ARRAY = VERSION.split('.').map(&:to_i) # :nodoc:
5
5
  VERSION_MAJOR = VERSION_ARRAY[0] # :nodoc:
6
6
  VERSION_MINOR = VERSION_ARRAY[1] # :nodoc:
@@ -223,4 +223,26 @@ describe AmpelExtase::Controller do
223
223
  end
224
224
  end
225
225
  end
226
+
227
+ describe '#expire_warning' do
228
+ let :aux do
229
+ double('Device')
230
+ end
231
+
232
+ before do
233
+ controller.instance_variable_set :@lights, double('Lights', aux: aux)
234
+ end
235
+
236
+ let :expire_warning do
237
+ controller.instance_eval { expire_warning }
238
+ end
239
+
240
+ it 'expires warnings after some time' do
241
+ allow(controller.instance_variable_get(:@warning_jenkins)).to\
242
+ receive(:state_changed_at).and_return Time.now - 65
243
+ expect(aux).to receive(:off)
244
+ expect(controller).to receive(:info).with('WARNING EXPIRED').and_call_original
245
+ expire_warning
246
+ end
247
+ end
226
248
  end
@@ -1,6 +1,11 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe AmpelExtase::JenkinsStateObserver do
4
+ before do
5
+ allow_any_instance_of(AmpelExtase::JenkinsClient).to receive(:puts)
6
+ allow_any_instance_of(AmpelExtase::JenkinsStateObserver).to receive(:puts)
7
+ end
8
+
4
9
  let :client do
5
10
  double('AmpelExtase::JenkinsClient', url: 'http://foo/bar')
6
11
  end
@@ -71,7 +76,11 @@ describe AmpelExtase::JenkinsStateObserver do
71
76
  end
72
77
 
73
78
  it 'tracks changes in build state' do
79
+ Time.dummy(past = Time.now - 10) do
80
+ jso
81
+ end
74
82
  expect(jso.instance_variable_get(:@build_state)).to eq bs_initial
83
+ expect(jso.state_changed_at).to eq past
75
84
  allow(client).to receive(:fetch_build).with(:last_completed_build).
76
85
  and_return('result' => 'SUCCESS')
77
86
  allow(client).to receive(:fetch_build).with(:last_build).
@@ -80,8 +89,15 @@ describe AmpelExtase::JenkinsStateObserver do
80
89
  "state changed from N/A to SUCCESS (building) => "\
81
90
  "taking action"
82
91
  )
83
- expect { |b| jso.on_state_change(&b) }.to yield_with_args(bs_success)
92
+ now = nil
93
+ Time.dummy(Time.now) do
94
+ expect { |b|
95
+ jso.on_state_change(&b)
96
+ now = Time.now
97
+ }.to yield_with_args(bs_success)
98
+ end
84
99
  expect(jso.instance_variable_get(:@build_state)).to eq bs_success
100
+ expect(jso.state_changed_at).to eq now
85
101
  allow(client).to receive(:fetch_build).with(:last_completed_build).
86
102
  and_return('result' => 'FAILURE')
87
103
  allow(client).to receive(:fetch_build).with(:last_build).
@@ -1,6 +1,10 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe AmpelExtase::JenkinsClient do
4
+ before do
5
+ allow_any_instance_of(AmpelExtase::JenkinsClient).to receive(:puts)
6
+ end
7
+
4
8
  let :client do
5
9
  AmpelExtase::JenkinsClient.new 'http://foo/bar'
6
10
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ampel_extase
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Florian Frank
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-25 00:00:00.000000000 Z
11
+ date: 2015-08-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gem_hadar
@@ -119,6 +119,7 @@ extra_rdoc_files:
119
119
  - lib/ampel_extase/build_state.rb
120
120
  - lib/ampel_extase/controller.rb
121
121
  - lib/ampel_extase/jenkins_client.rb
122
+ - lib/ampel_extase/jenkins_multi_state_observer.rb
122
123
  - lib/ampel_extase/jenkins_state_observer.rb
123
124
  - lib/ampel_extase/light_switcher.rb
124
125
  - lib/ampel_extase/version.rb
@@ -135,6 +136,7 @@ files:
135
136
  - lib/ampel_extase/build_state.rb
136
137
  - lib/ampel_extase/controller.rb
137
138
  - lib/ampel_extase/jenkins_client.rb
139
+ - lib/ampel_extase/jenkins_multi_state_observer.rb
138
140
  - lib/ampel_extase/jenkins_state_observer.rb
139
141
  - lib/ampel_extase/light_switcher.rb
140
142
  - lib/ampel_extase/version.rb
@@ -168,7 +170,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
168
170
  version: '0'
169
171
  requirements: []
170
172
  rubyforge_project:
171
- rubygems_version: 2.4.5.1
173
+ rubygems_version: 2.4.8
172
174
  signing_key:
173
175
  specification_version: 4
174
176
  summary: Library to control the build traffic light