build_status_server 0.9 → 0.10

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ coverage/
2
+ pkg/
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- build_status_server (0.8)
4
+ build_status_server (0.10)
5
5
  json
6
6
 
7
7
  GEM
@@ -12,22 +12,22 @@ GEM
12
12
  builder (>= 2.1.2)
13
13
  columnize (0.3.6)
14
14
  diff-lcs (1.1.3)
15
- json (1.6.5)
15
+ json (1.7.0)
16
16
  linecache (0.46)
17
17
  rbx-require-relative (> 0.0.4)
18
- rack (1.4.0)
18
+ rack (1.4.1)
19
19
  rack-protection (1.2.0)
20
20
  rack
21
21
  rake (0.9.2.2)
22
- rbx-require-relative (0.0.5)
23
- rspec (2.9.0)
24
- rspec-core (~> 2.9.0)
25
- rspec-expectations (~> 2.9.0)
26
- rspec-mocks (~> 2.9.0)
27
- rspec-core (2.9.0)
28
- rspec-expectations (2.9.0)
22
+ rbx-require-relative (0.0.9)
23
+ rspec (2.10.0)
24
+ rspec-core (~> 2.10.0)
25
+ rspec-expectations (~> 2.10.0)
26
+ rspec-mocks (~> 2.10.0)
27
+ rspec-core (2.10.0)
28
+ rspec-expectations (2.10.0)
29
29
  diff-lcs (~> 1.1.3)
30
- rspec-mocks (2.9.0)
30
+ rspec-mocks (2.10.1)
31
31
  ruby-debug (0.10.4)
32
32
  columnize (>= 0.1)
33
33
  ruby-debug-base (~> 0.10.4.0)
data/README.md CHANGED
@@ -21,7 +21,7 @@ application without any arguments, you will get a sample.
21
21
  # Execution
22
22
 
23
23
  See the options you can pass in by:
24
-
24
+
25
25
  $ build_status_server -h
26
26
 
27
27
  # Configuration file
@@ -48,8 +48,10 @@ Whether to display informative output messages.
48
48
 
49
49
  # Development
50
50
 
51
- `bin/build_status_server_traffic_light_mock` is provided for development
52
- purposes only.
51
+ `bin/test_tcp_server` is provided for development purposes only. It behaves
52
+ like the server on the
53
+ [Traffic Light controller](https://github.com/jcmuller/TrafficLightController)
54
+ project.
53
55
 
54
56
  # Finished product
55
57
  ![my image](http://i.imgur.com/aK5rs.jpg)
data/Rakefile ADDED
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env rake
2
+
3
+ $:.push File.expand_path("../lib", __FILE__)
4
+
5
+ require "rspec/core/rake_task"
6
+ require "build_status_server/version"
7
+ require "bundler/gem_tasks"
8
+
9
+ RSpec::Core::RakeTask.new(:spec) do |spec|
10
+ spec.pattern = "spec/**/*_spec.rb"
11
+ spec.rspec_opts = ["--backtrace --format CI::Reporter::RSpec"]
12
+ end
13
+
14
+ desc "Clean backup and swap files, and artifacts"
15
+ task :clean do
16
+ require "fileutils"
17
+ Dir["{pkg/*,**/*~,**/.*.sw?,coverage/**,spec/reports/**}"].each do |file|
18
+ rm_rf file
19
+ end
20
+ end
21
+
22
+ desc "Run rspec by default"
23
+ task :default => :spec
@@ -1,43 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'getoptlong'
4
-
5
- possible_arguments = [
6
- ['--config', '-c', GetoptLong::OPTIONAL_ARGUMENT],
7
- ['--development', '-d', GetoptLong::NO_ARGUMENT],
8
- ['--help', '-h', GetoptLong::NO_ARGUMENT],
9
- ['--verbose', '-v', GetoptLong::NO_ARGUMENT]
10
- ]
11
-
12
- opts = GetoptLong.new(*possible_arguments)
13
-
14
- options = {}
15
- showhelp = false
16
-
17
- opts.each do |opt, arg|
18
- case opt
19
- when '--development'
20
- $:.push 'lib'
21
- when '--help'
22
- puts <<-EOT
23
- #{File.basename(__FILE__)} [#{possible_arguments.map{|arg| arg[0] + (arg[2] == GetoptLong::OPTIONAL_ARGUMENT ? ' argument' : '')}.join('], [')}]
24
-
25
- All the arguments are optional.
26
-
27
- --config, -c Specify what configuration file to load
28
- --development, -d Whether we should load libraries from ./lib
29
- --help, -h Display this very helpful text
30
- --verbose, -v Be more informative about what's going on
31
-
32
- EOT
33
- exit
34
- when '--config'
35
- options[:config] = arg
36
- when '--verbose'
37
- options[:verbose] = true
38
- end
39
- end
40
-
3
+ $:.push 'lib'
41
4
  require 'build_status_server'
42
5
 
43
- BuildStatusServer::Server.new(options).listen
6
+ BuildStatusServer::CLI.new
@@ -5,11 +5,11 @@ Gem::Specification.new do |s|
5
5
  s.name = "build_status_server"
6
6
  s.version = BuildStatusServer::VERSION
7
7
  s.platform = Gem::Platform::RUBY
8
-
9
8
  s.author = "Juan C. Muller"
10
- s.email = "jcmuller@gmail.com"
9
+ s.email = "jcmuller@gmail.com"
11
10
  s.homepage = "http://github.com/jcmuller/build_status_server"
12
11
  s.license = "GPL"
12
+
13
13
  s.summary = <<-EOS
14
14
  This utility is part of an XFD (eXtreeme Feedback Device) solution designed and
15
15
  built for my employer ChallengePost (http://challengepost.com). It works in
@@ -19,21 +19,12 @@ Notification Plugin)) and an Arduino powered Traffic Light controller
19
19
  EOS
20
20
  s.description = "A build notifier server for Jenkins CI that controls an XFD over HTTP"
21
21
 
22
- s.files = Dir["{lib/**/*,spec/**/*.rb,spec/support/*}"] + %w(
23
- Gemfile
24
- Gemfile.lock
25
- LICENSE
26
- README.md
27
- bin/build_status_server
28
- build_status_server.gemspec
29
- config/config-example.yml
30
- )
31
-
22
+ s.files = `git ls-files`.split($\) - %w(.rspec bin/test_tcp_server)
32
23
  s.require_path = "lib"
33
- s.bindir = "bin"
34
- s.executables = %w(build_status_server)
24
+ s.bindir = "bin"
25
+ s.executables = %w(build_status_server)
35
26
 
36
- s.homepage = "http://github.com/jcmuller/build_status_server"
27
+ s.homepage = "http://github.com/jcmuller/build_status_server"
37
28
  s.test_files = Dir["spec/**/*_spec.rb"]
38
29
 
39
30
  s.add_development_dependency("rake")
@@ -0,0 +1,67 @@
1
+ require 'getoptlong'
2
+
3
+ module BuildStatusServer
4
+ class CLI
5
+ attr_reader :options
6
+
7
+ def initialize
8
+ process_command_line_options
9
+ BuildStatusServer::Server.new(options).listen
10
+ end
11
+
12
+ private
13
+
14
+ def process_command_line_options
15
+ @options = {}
16
+
17
+ possible_arguments = [
18
+ ['--config', '-c', GetoptLong::REQUIRED_ARGUMENT],
19
+ ['--help', '-h', GetoptLong::NO_ARGUMENT],
20
+ ['--verbose', '-v', GetoptLong::NO_ARGUMENT],
21
+ ['--version', '-V', GetoptLong::NO_ARGUMENT],
22
+ ]
23
+
24
+ GetoptLong.new(*possible_arguments).each do |opt, arg|
25
+ case opt
26
+ when '--help'
27
+ show_help_and_exit
28
+ when '--config'
29
+ options[:config] = arg
30
+ when '--verbose'
31
+ options[:verbose] = true
32
+ when '--version'
33
+ puts get_version
34
+ exit
35
+ end
36
+ end
37
+ end
38
+
39
+ def get_version
40
+ <<-EOV
41
+ #{get_program_name}, version #{BuildStatusServer::VERSION}
42
+
43
+ (c) Juan C. Muller, 2012
44
+ http://github.com/jcmuller/build_status_server
45
+ EOV
46
+ end
47
+
48
+ def show_help_and_exit
49
+ puts <<-EOT
50
+ Usage: #{get_program_name} [options]
51
+
52
+ Options:
53
+ -c, --config CONFIGURATION Specify what configuration file to load
54
+ -h, --help Display this very helpful text
55
+ -v, --verbose Be more informative about what's going on
56
+ -V, --version Print out current version info
57
+
58
+ #{get_version}
59
+ EOT
60
+ exit
61
+ end
62
+
63
+ def get_program_name
64
+ File.basename($0)
65
+ end
66
+ end
67
+ end
@@ -7,16 +7,16 @@ module BuildStatusServer
7
7
  config.load(options)
8
8
  end
9
9
 
10
- def listen
10
+ def listen(run_forever = true)
11
11
  setup_udp_server
12
12
 
13
13
  begin
14
- while true
14
+ while run_forever
15
15
  process_loop
16
16
  end
17
17
  rescue Interrupt
18
- puts "Good bye."
19
- sock.close
18
+ STDOUT.puts "Good bye."
19
+ udp_server.close
20
20
  exit
21
21
  end
22
22
  end
@@ -86,7 +86,6 @@ The address configured is not available (#{address})
86
86
  status = job["build"]["status"]
87
87
 
88
88
  if phase == "FINISHED"
89
- # Got SUCCESS for topic_action_master on Tue May 01 12:02:31 -0400 2012 []
90
89
  STDOUT.puts "Got #{status} for #{build_name} on #{Time.now} [#{job_internals(job)}]" if config.verbose
91
90
  case status
92
91
  when "SUCCESS", "FAILURE"
@@ -96,8 +95,6 @@ The address configured is not available (#{address})
96
95
  return true
97
96
  end
98
97
  else
99
- # Started for topic_action_master on Tue May 01 12:00:30 -0400 2012 [{"name"=>"topic_action_master", "url"=>"job/topic_action_master/", "build"=>{"number"=>98, "url"=>"job/topic_action_master/98/", "phase"= >"STARTED", "full_url"=>"http://ci.berman.challengepost.com/job/topic_action_master/98/"}}]
100
- # Started for topic_action_master on Tue May 01 12:02:31 -0400 2012 [{"name"=>"topic_action_master", "url"=>"job/topic_action_master/", "build"=>{"number"=>98, "url"=>"job/topic_action_master/98/", "status" =>"SUCCESS", "phase"=>"COMPLETED", "full_url"=>"http://ci.berman.challengepost.com/job/topic_action_master/98/"}}]
101
98
  STDOUT.puts "Started for #{build_name} on #{Time.now} [#{job_internals(job)}]" if config.verbose
102
99
  end
103
100
 
@@ -105,7 +102,9 @@ The address configured is not available (#{address})
105
102
  end
106
103
 
107
104
  def job_internals(job)
108
- "build=>#{job["build"]["number"]}, status=>#{job["build"]["status"]}"
105
+ "build=>#{job["build"]["number"]}".tap do |output|
106
+ output.concat(", status=>#{job["build"]["status"]}") if job["build"]["status"]
107
+ end
109
108
  end
110
109
 
111
110
  def should_process_build(build_name)
@@ -1,3 +1,3 @@
1
1
  module BuildStatusServer
2
- VERSION = "0.9"
2
+ VERSION = "0.10"
3
3
  end
@@ -5,6 +5,8 @@ require "timeout"
5
5
  require "yaml"
6
6
 
7
7
  module BuildStatusServer
8
- autoload :Config, 'build_status_server/config'
9
- autoload :Server, 'build_status_server/server'
8
+ autoload :CLI, 'build_status_server/cli'
9
+ autoload :Config, 'build_status_server/config'
10
+ autoload :Server, 'build_status_server/server'
11
+ autoload :VERSION, 'build_status_server/version'
10
12
  end
data/spec/.gitignore ADDED
@@ -0,0 +1 @@
1
+ reports/
@@ -8,7 +8,27 @@ describe BuildStatusServer::Server do
8
8
  STDERR.should_receive(:puts)
9
9
  end
10
10
 
11
- describe "#listen"
11
+ describe "#listen" do
12
+ it "should setup the udp server" do
13
+ server.should_receive(:setup_udp_server)
14
+ server.listen(false)
15
+ end
16
+
17
+ it "should close socket if interrupted" do
18
+ # inject interruption
19
+ server.should_receive(:process_loop).and_raise(Interrupt)
20
+
21
+ server.should_receive(:setup_udp_server)
22
+ udp_server = mock(:udp_server, :close => true)
23
+ server.should_receive(:udp_server).and_return(udp_server)
24
+
25
+ STDOUT.should_receive(:puts).with("Good bye.")
26
+ udp_server.should_receive(:close)
27
+ server.should_receive(:exit)
28
+
29
+ server.listen
30
+ end
31
+ end
12
32
 
13
33
  context "private methods" do
14
34
 
@@ -392,6 +412,18 @@ describe BuildStatusServer::Server do
392
412
  end
393
413
  end
394
414
 
415
+ describe "#job_internals" do
416
+ it "should return build number and status" do
417
+ params = {"build" => {"number" => "number", "status" => "status"}}
418
+ server.send(:job_internals, params).should == "build=>number, status=>status"
419
+ end
420
+
421
+ it "should return only build if no status" do
422
+ params = {"build" => {"number" => "number"}}
423
+ server.send(:job_internals, params).should == "build=>number"
424
+ end
425
+ end
426
+
395
427
  end
396
428
  end
397
429
 
@@ -0,0 +1,11 @@
1
+ {
2
+ "name":"test-master",
3
+ "url":"job/test/",
4
+ "build":{
5
+ "full_url":"http://cronus.local:3001/job/test/20/",
6
+ "number":20,
7
+ "phase":"FINISHED",
8
+ "status":"FAILURE",
9
+ "url":"job/test/21/"
10
+ }
11
+ }
@@ -0,0 +1,11 @@
1
+ {
2
+ "name":"test-development",
3
+ "url":"job/test/",
4
+ "build":{
5
+ "full_url":"http://cronus.local:3001/job/test/20/",
6
+ "number":20,
7
+ "phase":"FINISHED",
8
+ "status":"SUCCESS",
9
+ "url":"job/test/21/"
10
+ }
11
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "name":"test-master",
3
+ "url":"job/test/",
4
+ "build":{
5
+ "full_url":"http://cronus.local:3001/job/test/20/",
6
+ "number":20,
7
+ "phase":"STARTED",
8
+ "url":"job/test/21/"
9
+ }
10
+ }
File without changes
metadata CHANGED
@@ -1,12 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: build_status_server
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 31
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 9
9
- version: "0.9"
8
+ - 10
9
+ version: "0.10"
10
10
  platform: ruby
11
11
  authors:
12
12
  - Juan C. Muller
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2012-05-02 00:00:00 Z
17
+ date: 2012-05-05 00:00:00 Z
18
18
  dependencies:
19
19
  - !ruby/object:Gem::Dependency
20
20
  name: rake
@@ -81,26 +81,29 @@ extensions: []
81
81
  extra_rdoc_files: []
82
82
 
83
83
  files:
84
- - lib/build_status_server/config.html
85
- - lib/build_status_server/config.rb
86
- - lib/build_status_server/server.html
87
- - lib/build_status_server/server.rb
88
- - lib/build_status_server/version.html
89
- - lib/build_status_server/version.rb
90
- - lib/build_status_server.html
91
- - lib/build_status_server.rb
92
- - spec/lib/build_status_server/config_spec.rb
93
- - spec/lib/build_status_server/server_spec.rb
94
- - spec/spec_helper.rb
95
- - spec/support/build_result.yml
96
- - spec/support/sample.json
84
+ - .gitignore
97
85
  - Gemfile
98
86
  - Gemfile.lock
99
87
  - LICENSE
100
88
  - README.md
89
+ - Rakefile
101
90
  - bin/build_status_server
102
91
  - build_status_server.gemspec
103
92
  - config/config-example.yml
93
+ - lib/build_status_server.rb
94
+ - lib/build_status_server/cli.rb
95
+ - lib/build_status_server/config.rb
96
+ - lib/build_status_server/server.rb
97
+ - lib/build_status_server/version.rb
98
+ - spec/.gitignore
99
+ - spec/lib/build_status_server/config_spec.rb
100
+ - spec/lib/build_status_server/server_spec.rb
101
+ - spec/spec_helper.rb
102
+ - spec/support/build_result.yml
103
+ - spec/support/sample-failure.json
104
+ - spec/support/sample-ignored.json
105
+ - spec/support/sample-started.json
106
+ - spec/support/sample-success.json
104
107
  homepage: http://github.com/jcmuller/build_status_server
105
108
  licenses:
106
109
  - GPL
@@ -1,157 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <meta http-equiv="content-type" content="text/html;charset=utf-8">
5
- <title>config.rb</title>
6
- <link rel="stylesheet" href="http://jashkenas.github.com/docco/resources/docco.css">
7
- </head>
8
- <body>
9
- <div id='container'>
10
- <div id="background"></div>
11
- <div id="jump_to">
12
- Jump To &hellip;
13
- <div id="jump_wrapper">
14
- <div id="jump_page">
15
- <a class="source" href="../build_status_server.html">build_status_server.rb</a>
16
- <a class="source" href="config.html">config.rb</a>
17
- <a class="source" href="server.html">server.rb</a>
18
- <a class="source" href="version.html">version.rb</a>
19
- </div>
20
- </div>
21
- </div>
22
- <table cellspacing=0 cellpadding=0>
23
- <thead>
24
- <tr>
25
- <th class=docs><h1>config.rb</h1></th>
26
- <th class=code></th>
27
- </tr>
28
- </thead>
29
- <tbody>
30
- <tr id='section-1'>
31
- <td class=docs>
32
- <div class="pilwrap">
33
- <a class="pilcrow" href="#section-1">&#182;</a>
34
- </div>
35
-
36
- </td>
37
- <td class=code>
38
- <div class='highlight'><pre><span class="k">module</span> <span class="nn">BuildStatusServer</span>
39
- <span class="k">class</span> <span class="nc">Config</span>
40
- <span class="kp">attr_reader</span> <span class="ss">:config</span>
41
-
42
- <span class="k">def</span> <span class="nf">initialize</span>
43
- <span class="vi">@config</span> <span class="o">=</span> <span class="p">{}</span>
44
- <span class="k">end</span></pre></div>
45
- </td>
46
- </tr>
47
- <tr id='section-2'>
48
- <td class=docs>
49
- <div class="pilwrap">
50
- <a class="pilcrow" href="#section-2">&#182;</a>
51
- </div>
52
- <p>This is responsible of loading the config object</p>
53
- </td>
54
- <td class=code>
55
- <div class='highlight'><pre> <span class="k">def</span> <span class="nf">load</span><span class="p">(</span><span class="n">options</span> <span class="o">=</span> <span class="p">{})</span>
56
- <span class="n">config</span> <span class="o">=</span> <span class="n">load_config_file</span><span class="p">(</span><span class="n">options</span><span class="o">[</span><span class="ss">:config</span><span class="o">]</span><span class="p">)</span>
57
- <span class="n">import_config</span><span class="p">(</span><span class="n">config</span><span class="p">,</span> <span class="n">options</span><span class="p">)</span>
58
- <span class="k">end</span>
59
-
60
- <span class="k">def</span> <span class="nf">method_missing</span><span class="p">(</span><span class="n">meth</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">block</span><span class="p">)</span>
61
- <span class="k">return</span> <span class="n">config</span><span class="o">[</span><span class="n">meth</span><span class="o">.</span><span class="n">to_s</span><span class="o">]</span> <span class="k">if</span> <span class="n">config</span><span class="o">.</span><span class="n">has_key?</span><span class="p">(</span><span class="n">meth</span><span class="o">.</span><span class="n">to_s</span><span class="p">)</span>
62
- <span class="k">super</span>
63
- <span class="k">end</span>
64
-
65
- <span class="k">def</span> <span class="nf">store_file</span>
66
- <span class="k">return</span> <span class="no">File</span><span class="o">.</span><span class="n">expand_path</span><span class="p">(</span><span class="s2">&quot;.&quot;</span><span class="p">,</span> <span class="n">store</span><span class="o">[</span><span class="s2">&quot;filename&quot;</span><span class="o">]</span><span class="p">)</span> <span class="k">if</span> <span class="n">store</span>
67
- <span class="kp">nil</span>
68
- <span class="k">end</span>
69
-
70
- <span class="kp">private</span></pre></div>
71
- </td>
72
- </tr>
73
- <tr id='section-3'>
74
- <td class=docs>
75
- <div class="pilwrap">
76
- <a class="pilcrow" href="#section-3">&#182;</a>
77
- </div>
78
- <p>This will load the passed in config object into the config attribute</p>
79
- </td>
80
- <td class=code>
81
- <div class='highlight'><pre> <span class="k">def</span> <span class="nf">import_config</span><span class="p">(</span><span class="n">config</span> <span class="o">=</span> <span class="p">{},</span> <span class="n">options</span> <span class="o">=</span> <span class="p">{})</span>
82
- <span class="n">config</span><span class="o">[</span><span class="s2">&quot;verbose&quot;</span><span class="o">]</span> <span class="o">=</span> <span class="n">options</span><span class="o">[</span><span class="ss">:verbose</span><span class="o">]</span> <span class="k">unless</span> <span class="n">options</span><span class="o">[</span><span class="ss">:verbose</span><span class="o">].</span><span class="n">nil?</span>
83
- <span class="vi">@config</span> <span class="o">=</span> <span class="n">config</span>
84
- <span class="k">end</span></pre></div>
85
- </td>
86
- </tr>
87
- <tr id='section-4'>
88
- <td class=docs>
89
- <div class="pilwrap">
90
- <a class="pilcrow" href="#section-4">&#182;</a>
91
- </div>
92
- <p>This is responsible to return a hash with the contents of a YAML file</p>
93
-
94
- </td>
95
- <td class=code>
96
- <div class='highlight'><pre> <span class="k">def</span> <span class="nf">load_config_file</span><span class="p">(</span><span class="n">config_file</span> <span class="o">=</span> <span class="kp">nil</span><span class="p">)</span>
97
- <span class="n">curated_file</span> <span class="o">=</span> <span class="kp">nil</span>
98
-
99
- <span class="k">if</span> <span class="n">config_file</span>
100
- <span class="n">f</span> <span class="o">=</span> <span class="no">File</span><span class="o">.</span><span class="n">expand_path</span><span class="p">(</span><span class="n">config_file</span><span class="p">)</span>
101
- <span class="k">if</span> <span class="no">File</span><span class="o">.</span><span class="n">exists?</span><span class="p">(</span><span class="n">f</span><span class="p">)</span>
102
- <span class="n">curated_file</span> <span class="o">=</span> <span class="n">f</span>
103
- <span class="k">else</span>
104
- <span class="k">raise</span> <span class="s2">&quot;Supplied config file (</span><span class="si">#{</span><span class="n">config_file</span><span class="si">}</span><span class="s2">) doesn&#39;t seem to exist&quot;</span>
105
- <span class="k">end</span>
106
- <span class="k">else</span>
107
- <span class="n">locations_to_try</span><span class="o">.</span><span class="n">each</span> <span class="k">do</span> <span class="o">|</span><span class="n">possible_conf_file</span><span class="o">|</span>
108
- <span class="n">f</span> <span class="o">=</span> <span class="no">File</span><span class="o">.</span><span class="n">expand_path</span><span class="p">(</span><span class="n">possible_conf_file</span><span class="p">)</span>
109
- <span class="k">if</span> <span class="no">File</span><span class="o">.</span><span class="n">exists?</span><span class="p">(</span><span class="n">f</span><span class="p">)</span>
110
- <span class="n">curated_file</span> <span class="o">=</span> <span class="n">f</span>
111
- <span class="k">break</span>
112
- <span class="k">end</span>
113
- <span class="k">end</span>
114
-
115
- <span class="k">if</span> <span class="n">curated_file</span><span class="o">.</span><span class="n">nil?</span>
116
- <span class="no">STDERR</span><span class="o">.</span><span class="n">puts</span> <span class="o">&lt;&lt;-</span><span class="no">EOT</span>
117
- <span class="sh">Looks like there isn&#39;t an available configuration file for this program.</span>
118
- <span class="sh">We&#39;re very diligently going to use some sensible defaults, but you&#39;re</span>
119
- <span class="sh">strongly recommended to create one in any of the following locations:</span>
120
-
121
- <span class="sh"> #{locations_to_try.join(&quot;\n &quot;)}</span>
122
-
123
- <span class="sh"> Here is a sample of the contents for that file (and the settings we&#39;re going</span>
124
- <span class="sh"> to use):</span>
125
-
126
- <span class="sh">#{get_example_config}</span>
127
- <span class="no"> EOT</span>
128
-
129
- <span class="k">return</span> <span class="no">YAML</span><span class="o">.</span><span class="n">load</span><span class="p">(</span><span class="n">get_example_config</span><span class="p">)</span>
130
- <span class="k">end</span>
131
- <span class="k">end</span>
132
-
133
- <span class="no">YAML</span><span class="o">.</span><span class="n">load_file</span><span class="p">(</span><span class="n">curated_file</span><span class="p">)</span><span class="o">.</span><span class="n">tap</span> <span class="k">do</span> <span class="o">|</span><span class="n">config</span><span class="o">|</span>
134
- <span class="k">raise</span> <span class="s2">&quot;This is an invalid configuration file!&quot;</span> <span class="k">unless</span> <span class="n">config</span><span class="o">.</span><span class="n">class</span> <span class="o">==</span> <span class="no">Hash</span>
135
- <span class="k">end</span>
136
- <span class="k">end</span>
137
-
138
- <span class="k">def</span> <span class="nf">locations_to_try</span>
139
- <span class="sx">%w(</span>
140
- <span class="sx"> ~/.config/build_status_server/config.yml</span>
141
- <span class="sx"> ./config/config.yml</span>
142
- <span class="sx"> /etc/build_status_server/config.yml</span>
143
- <span class="sx"> /usr/local/etc/build_status_server/config.yml</span>
144
- <span class="sx"> )</span>
145
- <span class="k">end</span>
146
-
147
- <span class="k">def</span> <span class="nf">get_example_config</span>
148
- <span class="n">filename</span> <span class="o">=</span> <span class="s2">&quot;</span><span class="si">#{</span><span class="no">File</span><span class="o">.</span><span class="n">dirname</span><span class="p">(</span><span class="no">File</span><span class="o">.</span><span class="n">expand_path</span><span class="p">(</span><span class="bp">__FILE__</span><span class="p">))</span><span class="si">}</span><span class="s2">/../../config/config-example.yml&quot;</span>
149
- <span class="no">File</span><span class="o">.</span><span class="n">open</span><span class="p">(</span><span class="n">filename</span><span class="p">)</span><span class="o">.</span><span class="n">read</span>
150
- <span class="k">end</span>
151
- <span class="k">end</span>
152
- <span class="k">end</span></pre></div>
153
- </td>
154
- </tr>
155
- </table>
156
- </div>
157
- </body>
@@ -1,202 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <meta http-equiv="content-type" content="text/html;charset=utf-8">
5
- <title>server.rb</title>
6
- <link rel="stylesheet" href="http://jashkenas.github.com/docco/resources/docco.css">
7
- </head>
8
- <body>
9
- <div id='container'>
10
- <div id="background"></div>
11
- <div id="jump_to">
12
- Jump To &hellip;
13
- <div id="jump_wrapper">
14
- <div id="jump_page">
15
- <a class="source" href="../build_status_server.html">build_status_server.rb</a>
16
- <a class="source" href="config.html">config.rb</a>
17
- <a class="source" href="server.html">server.rb</a>
18
- <a class="source" href="version.html">version.rb</a>
19
- </div>
20
- </div>
21
- </div>
22
- <table cellspacing=0 cellpadding=0>
23
- <thead>
24
- <tr>
25
- <th class=docs><h1>server.rb</h1></th>
26
- <th class=code></th>
27
- </tr>
28
- </thead>
29
- <tbody>
30
- <tr id='section-1'>
31
- <td class=docs>
32
- <div class="pilwrap">
33
- <a class="pilcrow" href="#section-1">&#182;</a>
34
- </div>
35
- <p>TODO
36
- move all configuration stuff to Config
37
- and just call config[:blaj] instead of if blah</p>
38
-
39
- </td>
40
- <td class=code>
41
- <div class='highlight'><pre><span class="k">module</span> <span class="nn">BuildStatusServer</span>
42
- <span class="k">class</span> <span class="nc">Server</span>
43
- <span class="kp">attr_reader</span> <span class="ss">:config</span><span class="p">,</span> <span class="ss">:store</span>
44
-
45
- <span class="k">def</span> <span class="nf">initialize</span><span class="p">(</span><span class="n">options</span> <span class="o">=</span> <span class="p">{})</span>
46
- <span class="vi">@config</span> <span class="o">=</span> <span class="no">Config</span><span class="o">.</span><span class="n">new</span>
47
- <span class="n">config</span><span class="o">.</span><span class="n">load</span><span class="p">(</span><span class="n">options</span><span class="p">)</span>
48
- <span class="k">end</span>
49
-
50
- <span class="k">def</span> <span class="nf">listen</span>
51
- <span class="n">sock</span> <span class="o">=</span> <span class="no">UDPSocket</span><span class="o">.</span><span class="n">new</span>
52
- <span class="n">udp_server</span> <span class="o">=</span> <span class="n">config</span><span class="o">.</span><span class="n">udp_server</span>
53
-
54
- <span class="k">begin</span>
55
- <span class="n">sock</span><span class="o">.</span><span class="n">bind</span><span class="p">(</span><span class="n">udp_server</span><span class="o">[</span><span class="s2">&quot;address&quot;</span><span class="o">]</span><span class="p">,</span> <span class="n">udp_server</span><span class="o">[</span><span class="s2">&quot;port&quot;</span><span class="o">]</span><span class="p">)</span>
56
- <span class="k">rescue</span> <span class="no">Errno</span><span class="o">::</span><span class="no">EADDRINUSE</span>
57
- <span class="no">STDERR</span><span class="o">.</span><span class="n">puts</span> <span class="o">&lt;&lt;-</span><span class="no">EOT</span>
58
- <span class="sh">There appears that another instance is running, or another process</span>
59
- <span class="sh">is listening at the same port (#{udp_server[&quot;address&quot;]}:#{udp_server[&quot;port&quot;]}</span>
60
-
61
- <span class="no"> EOT</span>
62
- <span class="nb">exit</span>
63
- <span class="k">end</span>
64
-
65
- <span class="nb">puts</span> <span class="s2">&quot;Listening on UDP </span><span class="si">#{</span><span class="n">udp_server</span><span class="o">[</span><span class="s2">&quot;address&quot;</span><span class="o">]</span><span class="si">}</span><span class="s2">:</span><span class="si">#{</span><span class="n">udp_server</span><span class="o">[</span><span class="s2">&quot;port&quot;</span><span class="o">]</span><span class="si">}</span><span class="s2">&quot;</span> <span class="k">if</span> <span class="n">config</span><span class="o">.</span><span class="n">verbose</span>
66
-
67
- <span class="k">begin</span>
68
- <span class="k">while</span> <span class="kp">true</span>
69
- <span class="n">data</span><span class="p">,</span> <span class="n">addr</span> <span class="o">=</span> <span class="n">sock</span><span class="o">.</span><span class="n">recvfrom</span><span class="p">(</span><span class="mi">2048</span><span class="p">)</span>
70
-
71
- <span class="k">if</span> <span class="n">process_job</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
72
- <span class="n">status</span> <span class="o">=</span> <span class="n">process_all_statuses</span>
73
- <span class="n">notify</span><span class="p">(</span><span class="n">status</span><span class="p">)</span>
74
- <span class="k">end</span>
75
- <span class="k">end</span>
76
- <span class="k">rescue</span> <span class="no">Interrupt</span>
77
- <span class="nb">puts</span> <span class="s2">&quot;Good bye.&quot;</span>
78
- <span class="n">sock</span><span class="o">.</span><span class="n">close</span>
79
- <span class="nb">exit</span>
80
- <span class="k">end</span>
81
- <span class="k">end</span>
82
-
83
- <span class="kp">private</span>
84
-
85
- <span class="k">def</span> <span class="nf">load_store</span>
86
- <span class="vi">@store</span> <span class="o">=</span> <span class="k">begin</span>
87
- <span class="no">YAML</span><span class="o">.</span><span class="n">load_file</span><span class="p">(</span><span class="n">config</span><span class="o">.</span><span class="n">store_file</span><span class="p">)</span>
88
- <span class="k">rescue</span>
89
- <span class="p">{}</span>
90
- <span class="k">end</span>
91
- <span class="vi">@store</span> <span class="o">=</span> <span class="p">{}</span> <span class="k">unless</span> <span class="n">store</span><span class="o">.</span><span class="n">class</span> <span class="o">==</span> <span class="no">Hash</span>
92
- <span class="k">end</span>
93
-
94
-
95
- <span class="k">def</span> <span class="nf">process_job</span><span class="p">(</span><span class="n">data</span> <span class="o">=</span> <span class="s2">&quot;{}&quot;</span><span class="p">)</span>
96
- <span class="n">job</span> <span class="o">=</span> <span class="no">JSON</span><span class="o">.</span><span class="n">parse</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
97
-
98
- <span class="n">build_name</span> <span class="o">=</span> <span class="n">job</span><span class="o">[</span><span class="s2">&quot;name&quot;</span><span class="o">]</span>
99
-
100
- <span class="k">unless</span> <span class="n">should_process_build</span><span class="p">(</span><span class="n">build_name</span><span class="p">)</span>
101
- <span class="no">STDOUT</span><span class="o">.</span><span class="n">puts</span> <span class="s2">&quot;Ignoring </span><span class="si">#{</span><span class="n">build_name</span><span class="si">}</span><span class="s2"> (</span><span class="si">#{</span><span class="n">config</span><span class="o">.</span><span class="n">mask</span><span class="o">[</span><span class="s2">&quot;regex&quot;</span><span class="o">]</span><span class="si">}</span><span class="s2">--</span><span class="si">#{</span><span class="n">config</span><span class="o">.</span><span class="n">mask</span><span class="o">[</span><span class="s2">&quot;policy&quot;</span><span class="o">]</span><span class="si">}</span><span class="s2">)&quot;</span> <span class="k">if</span> <span class="n">config</span><span class="o">.</span><span class="n">verbose</span>
102
- <span class="k">return</span> <span class="kp">false</span>
103
- <span class="k">end</span>
104
-
105
- <span class="k">if</span> <span class="n">job</span><span class="o">.</span><span class="n">class</span> <span class="o">!=</span> <span class="no">Hash</span> <span class="ow">or</span>
106
- <span class="n">job</span><span class="o">[</span><span class="s2">&quot;build&quot;</span><span class="o">].</span><span class="n">class</span> <span class="o">!=</span> <span class="no">Hash</span>
107
- <span class="no">STDERR</span><span class="o">.</span><span class="n">puts</span> <span class="s2">&quot;Pinged with an invalid payload&quot;</span>
108
- <span class="k">return</span> <span class="kp">false</span>
109
- <span class="k">end</span>
110
-
111
- <span class="n">phase</span> <span class="o">=</span> <span class="n">job</span><span class="o">[</span><span class="s2">&quot;build&quot;</span><span class="o">][</span><span class="s2">&quot;phase&quot;</span><span class="o">]</span>
112
- <span class="n">status</span> <span class="o">=</span> <span class="n">job</span><span class="o">[</span><span class="s2">&quot;build&quot;</span><span class="o">][</span><span class="s2">&quot;status&quot;</span><span class="o">]</span>
113
-
114
- <span class="k">if</span> <span class="n">phase</span> <span class="o">==</span> <span class="s2">&quot;FINISHED&quot;</span>
115
- <span class="no">STDOUT</span><span class="o">.</span><span class="n">puts</span> <span class="s2">&quot;Got </span><span class="si">#{</span><span class="n">status</span><span class="si">}</span><span class="s2"> for </span><span class="si">#{</span><span class="n">build_name</span><span class="si">}</span><span class="s2"> on </span><span class="si">#{</span><span class="no">Time</span><span class="o">.</span><span class="n">now</span><span class="si">}</span><span class="s2"> [</span><span class="si">#{</span><span class="n">job</span><span class="o">.</span><span class="n">inspect</span><span class="si">}</span><span class="s2">]&quot;</span> <span class="k">if</span> <span class="n">config</span><span class="o">.</span><span class="n">verbose</span>
116
- <span class="k">case</span> <span class="n">status</span>
117
- <span class="k">when</span> <span class="s2">&quot;SUCCESS&quot;</span><span class="p">,</span> <span class="s2">&quot;FAILURE&quot;</span>
118
- <span class="n">load_store</span>
119
- <span class="n">store</span><span class="o">[</span><span class="n">build_name</span><span class="o">]</span> <span class="o">=</span> <span class="n">status</span>
120
- <span class="no">File</span><span class="o">.</span><span class="n">open</span><span class="p">(</span><span class="n">config</span><span class="o">.</span><span class="n">store_file</span><span class="p">,</span> <span class="s2">&quot;w&quot;</span><span class="p">)</span> <span class="p">{</span> <span class="o">|</span><span class="n">file</span><span class="o">|</span> <span class="no">YAML</span><span class="o">.</span><span class="n">dump</span><span class="p">(</span><span class="n">store</span><span class="p">,</span> <span class="n">file</span><span class="p">)</span> <span class="p">}</span>
121
- <span class="k">return</span> <span class="kp">true</span>
122
- <span class="k">end</span>
123
- <span class="k">else</span>
124
- <span class="no">STDOUT</span><span class="o">.</span><span class="n">puts</span> <span class="s2">&quot;Started for </span><span class="si">#{</span><span class="n">build_name</span><span class="si">}</span><span class="s2"> on </span><span class="si">#{</span><span class="no">Time</span><span class="o">.</span><span class="n">now</span><span class="si">}</span><span class="s2"> [</span><span class="si">#{</span><span class="n">job</span><span class="o">.</span><span class="n">inspect</span><span class="si">}</span><span class="s2">]&quot;</span> <span class="k">if</span> <span class="n">config</span><span class="o">.</span><span class="n">verbose</span>
125
- <span class="k">end</span>
126
-
127
- <span class="k">return</span> <span class="kp">false</span>
128
- <span class="k">end</span>
129
-
130
- <span class="k">def</span> <span class="nf">should_process_build</span><span class="p">(</span><span class="n">build_name</span><span class="p">)</span>
131
- <span class="c1"># If mask exists, then ...</span>
132
- <span class="o">!</span> <span class="p">(</span>
133
- <span class="o">!!</span><span class="n">config</span><span class="o">.</span><span class="n">mask</span> <span class="o">&amp;&amp;</span>
134
- <span class="o">!!</span><span class="n">config</span><span class="o">.</span><span class="n">mask</span><span class="o">[</span><span class="s2">&quot;regex&quot;</span><span class="o">]</span> <span class="o">&amp;&amp;</span>
135
- <span class="p">((</span><span class="n">config</span><span class="o">.</span><span class="n">mask</span><span class="o">[</span><span class="s2">&quot;policy&quot;</span><span class="o">]</span> <span class="o">==</span> <span class="s2">&quot;include&quot;</span> <span class="o">&amp;&amp;</span> <span class="n">build_name</span> <span class="o">!~</span> <span class="n">config</span><span class="o">.</span><span class="n">mask</span><span class="o">[</span><span class="s2">&quot;regex&quot;</span><span class="o">]</span><span class="p">)</span> <span class="o">||</span>
136
- <span class="p">(</span><span class="n">config</span><span class="o">.</span><span class="n">mask</span><span class="o">[</span><span class="s2">&quot;policy&quot;</span><span class="o">]</span> <span class="o">!=</span> <span class="s2">&quot;include&quot;</span> <span class="o">&amp;&amp;</span> <span class="n">build_name</span> <span class="o">=~</span> <span class="n">config</span><span class="o">.</span><span class="n">mask</span><span class="o">[</span><span class="s2">&quot;regex&quot;</span><span class="o">]</span><span class="p">)</span>
137
- <span class="p">))</span>
138
- <span class="k">end</span>
139
-
140
- <span class="k">def</span> <span class="nf">process_all_statuses</span>
141
- <span class="n">pass</span> <span class="o">=</span> <span class="kp">true</span>
142
-
143
- <span class="vi">@store</span><span class="o">.</span><span class="n">values</span><span class="o">.</span><span class="n">each</span> <span class="k">do</span> <span class="o">|</span><span class="n">val</span><span class="o">|</span>
144
- <span class="n">pass</span> <span class="o">&amp;&amp;=</span> <span class="p">(</span><span class="n">val</span> <span class="o">==</span> <span class="s2">&quot;pass&quot;</span> <span class="o">||</span> <span class="n">val</span> <span class="o">==</span> <span class="s2">&quot;SUCCESS&quot;</span><span class="p">)</span>
145
- <span class="k">end</span>
146
-
147
- <span class="n">pass</span>
148
- <span class="k">end</span>
149
-
150
- <span class="k">def</span> <span class="nf">notify</span><span class="p">(</span><span class="n">status</span><span class="p">)</span>
151
- <span class="n">tcp_client</span> <span class="o">=</span> <span class="n">config</span><span class="o">.</span><span class="n">tcp_client</span>
152
-
153
- <span class="n">attempts</span> <span class="o">=</span> <span class="mi">0</span>
154
- <span class="n">light</span> <span class="o">=</span> <span class="n">status</span> <span class="p">?</span> <span class="n">tcp_client</span><span class="o">[</span><span class="s2">&quot;pass&quot;</span><span class="o">]</span> <span class="p">:</span> <span class="n">tcp_client</span><span class="o">[</span><span class="s2">&quot;fail&quot;</span><span class="o">]</span>
155
-
156
- <span class="k">begin</span>
157
- <span class="n">timeout</span><span class="p">(</span><span class="mi">5</span><span class="p">)</span> <span class="k">do</span>
158
- <span class="n">attempts</span> <span class="o">+=</span> <span class="mi">1</span>
159
- <span class="n">client</span> <span class="o">=</span> <span class="no">TCPSocket</span><span class="o">.</span><span class="n">new</span><span class="p">(</span><span class="n">tcp_client</span><span class="o">[</span><span class="s2">&quot;host&quot;</span><span class="o">]</span><span class="p">,</span> <span class="n">tcp_client</span><span class="o">[</span><span class="s2">&quot;port&quot;</span><span class="o">]</span><span class="p">)</span>
160
- <span class="n">client</span><span class="o">.</span><span class="n">print</span> <span class="s2">&quot;GET </span><span class="si">#{</span><span class="n">light</span><span class="si">}</span><span class="s2"> HTTP/1.0</span><span class="se">\n\n</span><span class="s2">&quot;</span>
161
- <span class="n">answer</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">gets</span><span class="p">(</span><span class="kp">nil</span><span class="p">)</span>
162
- <span class="no">STDOUT</span><span class="o">.</span><span class="n">puts</span> <span class="n">answer</span> <span class="k">if</span> <span class="n">config</span><span class="o">.</span><span class="n">verbose</span>
163
- <span class="n">client</span><span class="o">.</span><span class="n">close</span>
164
- <span class="k">end</span>
165
- <span class="k">rescue</span> <span class="no">Timeout</span><span class="o">::</span><span class="no">Error</span> <span class="o">=&gt;</span> <span class="n">ex</span>
166
- <span class="no">STDERR</span><span class="o">.</span><span class="n">puts</span> <span class="s2">&quot;Error: </span><span class="si">#{</span><span class="n">ex</span><span class="si">}</span><span class="s2"> while trying to send </span><span class="si">#{</span><span class="n">light</span><span class="si">}</span><span class="s2">&quot;</span>
167
- <span class="k">retry</span> <span class="k">unless</span> <span class="n">attempts</span> <span class="o">&gt;</span> <span class="mi">2</span>
168
- <span class="k">rescue</span> <span class="no">Errno</span><span class="o">::</span><span class="no">ECONNREFUSED</span><span class="p">,</span> <span class="no">Errno</span><span class="o">::</span><span class="no">EHOSTUNREACH</span> <span class="o">=&gt;</span> <span class="n">ex</span>
169
- <span class="no">STDERR</span><span class="o">.</span><span class="n">puts</span> <span class="s2">&quot;Error: </span><span class="si">#{</span><span class="n">ex</span><span class="si">}</span><span class="s2"> while trying to send </span><span class="si">#{</span><span class="n">light</span><span class="si">}</span><span class="s2">&quot;</span>
170
- <span class="no">STDERR</span><span class="o">.</span><span class="n">puts</span> <span class="s2">&quot;Will wait for 2 seconds and try again...&quot;</span>
171
- <span class="nb">sleep</span> <span class="mi">2</span>
172
- <span class="k">retry</span> <span class="k">unless</span> <span class="n">attempts</span> <span class="o">&gt;</span> <span class="mi">2</span>
173
- <span class="k">end</span>
174
- <span class="k">end</span>
175
- <span class="k">end</span>
176
- <span class="k">end</span>
177
-
178
- <span class="cp">__END__</span>
179
-
180
- <span class="cp">Example payload:</span>
181
- <span class="cp">{</span>
182
- <span class="cp"> &quot;name&quot;:&quot;test&quot;,</span>
183
- <span class="cp"> &quot;url&quot;:&quot;job/test/&quot;,</span>
184
- <span class="cp"> &quot;build&quot;:{</span>
185
- <span class="cp"> &quot;full_url&quot;:&quot;http://cronus.local:3001/job/test/20/&quot;,</span>
186
- <span class="cp"> &quot;number&quot;:20,</span>
187
- <span class="cp"> &quot;phase&quot;:&quot;FINISHED&quot;,</span>
188
- <span class="cp"> &quot;status&quot;:&quot;SUCCESS&quot;,</span>
189
- <span class="cp"> &quot;url&quot;:&quot;job/test/20/&quot;</span>
190
- <span class="cp"> }</span>
191
- <span class="cp">}</span>
192
-
193
- <span class="cp">We&#39;re getting this error once in a while:</span>
194
- <span class="cp">/usr/local/lib/ruby/1.8/timeout.rb:64:in `notify&#39;: execution expired (Timeout::Error)</span>
195
- <span class="cp"> from /home/jcmuller/build_notifier/lib/server.rb:102:in `notify&#39;</span>
196
- <span class="cp"> from /home/jcmuller/build_notifier/lib/server.rb:33:in `listen&#39;</span>
197
- <span class="cp"> from bin/server:5</span></pre></div>
198
- </td>
199
- </tr>
200
- </table>
201
- </div>
202
- </body>
@@ -1,32 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <meta http-equiv="content-type" content="text/html;charset=utf-8">
5
- <title>version.rb</title>
6
- <link rel="stylesheet" href="http://jashkenas.github.com/docco/resources/docco.css">
7
- </head>
8
- <body>
9
- <div id='container'>
10
- <div id="background"></div>
11
- <div id="jump_to">
12
- Jump To &hellip;
13
- <div id="jump_wrapper">
14
- <div id="jump_page">
15
- <a class="source" href="../build_status_server.html">build_status_server.rb</a>
16
- <a class="source" href="config.html">config.rb</a>
17
- <a class="source" href="server.html">server.rb</a>
18
- <a class="source" href="version.html">version.rb</a>
19
- </div>
20
- </div>
21
- </div>
22
- <table cellspacing=0 cellpadding=0>
23
- <thead>
24
- <tr>
25
- <th class=docs><h1>version.rb</h1></th>
26
- <th class=code></th>
27
- </tr>
28
- </thead>
29
- <tbody>
30
- </table>
31
- </div>
32
- </body>
@@ -1,118 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <meta http-equiv="content-type" content="text/html;charset=utf-8">
5
- <title>build_status_server.rb</title>
6
- <link rel="stylesheet" href="http://jashkenas.github.com/docco/resources/docco.css">
7
- </head>
8
- <body>
9
- <div id='container'>
10
- <div id="background"></div>
11
- <div id="jump_to">
12
- Jump To &hellip;
13
- <div id="jump_wrapper">
14
- <div id="jump_page">
15
- <a class="source" href="build_status_server.html">build_status_server.rb</a>
16
- <a class="source" href="build_status_server/config.html">config.rb</a>
17
- <a class="source" href="build_status_server/server.html">server.rb</a>
18
- <a class="source" href="build_status_server/version.html">version.rb</a>
19
- </div>
20
- </div>
21
- </div>
22
- <table cellspacing=0 cellpadding=0>
23
- <thead>
24
- <tr>
25
- <th class=docs><h1>build_status_server.rb</h1></th>
26
- <th class=code></th>
27
- </tr>
28
- </thead>
29
- <tbody>
30
- <tr id='section-Installation'>
31
- <td class=docs>
32
- <div class="pilwrap">
33
- <a class="pilcrow" href="#section-Installation">&#182;</a>
34
- </div>
35
- <p><strong>Build Notifier</strong></p>
36
-
37
- <p>This utility is part of an XFD (eXtreeme Feedback Device) solution designed and
38
- built for my employer <a href="http://challengepost.com">ChallengePost</a>. It works in
39
- conjunction with our <a href="http://jenkins-ci.org">Jenkins</a> Continuous Integration
40
- server (and its
41
- <a href="https://wiki.jenkins-ci.org/display/JENKINS/Notification+Plugin">Notification Plugin</a>)
42
- and an <a href="http://arduino.cc">Arduino</a> powered
43
- <a href="https://github.com/jcmuller/TrafficLightController">Traffic Light controller</a>
44
- with a
45
- pseudo-<a href="http://en.wikipedia.org/wiki/Representational_state_transfer">REST</a>ful
46
- API.</p>
47
-
48
- <p>To run, you need to create a <code>config.yml</code> file. The first time you run the
49
- application without any arguments, you will get a sample.</p>
50
-
51
- <h1>Installation</h1>
52
-
53
- <p>$ gem install build<em>status</em>server</p>
54
-
55
- <h1>Execution</h1>
56
-
57
- <p>See the options you can pass in by:</p>
58
-
59
- <p>$ build<em>status</em>server -h</p>
60
-
61
- <h1>Configuration file</h1>
62
-
63
- <h2>UDP Server</h2>
64
-
65
- <p>This section defines what interface and port should the UDP server listen at.
66
- The Jenkins&#39; Notification Plugin should be set to this parameters as well.</p>
67
-
68
- <h2>TCP Client</h2>
69
-
70
- <p>This section is where we tell the server how to communicate with the web
71
- enabled XFD. In the example case, there is a web server running somewhere
72
- listening on port 4567 that responds to <code>/green</code> and <code>/red</code>.</p>
73
-
74
- <p>On our installation, this represents the Traffic Light&#39;s Arduino web server.</p>
75
-
76
- <h2>Store</h2>
77
-
78
- <p>Where the persistent state will be stored.</p>
79
-
80
- <h2>Mask (optional)</h2>
81
-
82
- <p>You can decide to either include or ignore certain builds whose names match a
83
- given <a href="http://en.wikipedia.org/wiki/Regular_expression">Regular Expression</a>.</p>
84
-
85
- <h2>Verbose</h2>
86
-
87
- <p>Whether to display informative output messages.</p>
88
-
89
- <h1>Development</h1>
90
-
91
- <p><code>bin/build_status_server_traffic_light_mock</code> is provided for development
92
- purposes only.</p>
93
-
94
- <h1>Finished product</h1>
95
-
96
- <p><img src="http://i.imgur.com/aK5rs.jpg" alt="my image"></p>
97
-
98
- <h1>Wiring the traffic light</h1>
99
-
100
- <p><img src="http://i.imgur.com/gUpWe.jpg" alt="my image"></p>
101
-
102
- </td>
103
- <td class=code>
104
- <div class='highlight'><pre><span class="nb">require</span> <span class="s2">&quot;rubygems&quot;</span>
105
- <span class="nb">require</span> <span class="s2">&quot;json&quot;</span>
106
- <span class="nb">require</span> <span class="s2">&quot;socket&quot;</span>
107
- <span class="nb">require</span> <span class="s2">&quot;timeout&quot;</span>
108
- <span class="nb">require</span> <span class="s2">&quot;yaml&quot;</span>
109
-
110
- <span class="k">module</span> <span class="nn">BuildStatusServer</span>
111
- <span class="nb">autoload</span> <span class="ss">:Config</span><span class="p">,</span> <span class="s1">&#39;build_status_server/config&#39;</span>
112
- <span class="nb">autoload</span> <span class="ss">:Server</span><span class="p">,</span> <span class="s1">&#39;build_status_server/server&#39;</span>
113
- <span class="k">end</span></pre></div>
114
- </td>
115
- </tr>
116
- </table>
117
- </div>
118
- </body>