From 1d6a6e44ce969daa44b10f72e0848a9c66699fad Mon Sep 17 00:00:00 2001 From: Team OD Date: Wed, 11 Mar 2009 20:05:33 -0400 Subject: [PATCH] add missing model --- Rakefile | 10 ++++ app/models/scheduler.rb | 78 +++++++++++++++++++++++++++++++ app/models/scheduler.rb~ | 1 - test/XmlStatusReport.aspx | 6 +++ test/cctray.xml | 15 ++++++ test/fixtures/schedulers.yml | 7 +++ test/performance/browsing_test.rb | 9 ++++ test/test_helper.rb | 38 +++++++++++++++ 8 files changed, 163 insertions(+), 1 deletion(-) create mode 100644 Rakefile create mode 100644 app/models/scheduler.rb create mode 100644 test/XmlStatusReport.aspx create mode 100644 test/cctray.xml create mode 100644 test/fixtures/schedulers.yml create mode 100644 test/performance/browsing_test.rb create mode 100644 test/test_helper.rb diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..3bb0e85 --- /dev/null +++ b/Rakefile @@ -0,0 +1,10 @@ +# Add your own tasks in files placed in lib/tasks ending in .rake, +# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. + +require(File.join(File.dirname(__FILE__), 'config', 'boot')) + +require 'rake' +require 'rake/testtask' +require 'rake/rdoctask' + +require 'tasks/rails' diff --git a/app/models/scheduler.rb b/app/models/scheduler.rb new file mode 100644 index 0000000..82f8cbe --- /dev/null +++ b/app/models/scheduler.rb @@ -0,0 +1,78 @@ +require 'rubygems' +require 'hpricot' +require 'open-uri' +require 'rufus/scheduler' + +# Uses the rufus scheduler to check for builds that passed or failed. Performs X10 action with bottlerocket's 'br' command + +class Scheduler + include Singleton + + def start + @last = {} + @failing_builds = Set.new + + scheduler = Rufus::Scheduler.start_new + scheduler.every "10s" do + parse(Conf.ruby1_url) + parse(Conf.build1_url) + end + end + + + def parse(url) + file = open(url); + doc = Hpricot.XML(file) + file.close + # name="2008-07-25-homepage" activity="Sleeping" lastBuildStatus="Failure" lastBuildLabel="" lastBuildTime="2008-10-01T20:51:46" + doc.search("/projects/project").each do |project| + project_name = project.attributes["name"] + status = project.attributes["lastBuildStatus"] + time = project.attributes["lastBuildTime"] + + followed_builds = Conf.branches.split(",").map {|x| x.strip} + + if followed_builds.include?(project_name) + previous_build = @last[project_name] + @last[project_name] = {"project" => project_name, "time" => time, "status" => status} + + if status.include?("Fail") + @failing_builds << project_name + on_fail(project_name) + elsif !previous_build.nil? && (previous_build["time"] != time) && status.include?("Success") + @failing_builds.delete(project_name) + if (!previous_build["status"].include?("Fail")) + on_pass(project_name) + off_pass + off_pass + elsif @failing_builds.empty? + off_fail + end + end + end + end + end + + def on_pass(project_name) + puts "#{project_name} Bubbles!!!!!" + system("br #{Conf.x10_house_code}#{Conf.x10_pass_device} ON") + sleep 3 + end + + def off_pass + puts "Bubbles Off" + system("br #{Conf.x10_house_code}#{Conf.x10_pass_device} OFF") + sleep 2 + end + + def on_fail(project_name) + puts "#{project_name} Red Light!!!" + system("br #{Conf.x10_house_code}#{Conf.x10_failure_device} ON") + end + + def off_fail + puts "Light Off" + system("br #{Conf.x10_house_code}#{Conf.x10_failure_device} OFF") + end + +end diff --git a/app/models/scheduler.rb~ b/app/models/scheduler.rb~ index 07fea3b..82f8cbe 100644 --- a/app/models/scheduler.rb~ +++ b/app/models/scheduler.rb~ @@ -4,7 +4,6 @@ require 'open-uri' require 'rufus/scheduler' # Uses the rufus scheduler to check for builds that passed or failed. Performs X10 action with bottlerocket's 'br' command -# Author: Patrick Foley class Scheduler include Singleton diff --git a/test/XmlStatusReport.aspx b/test/XmlStatusReport.aspx new file mode 100644 index 0000000..e306873 --- /dev/null +++ b/test/XmlStatusReport.aspx @@ -0,0 +1,6 @@ + + + + + + diff --git a/test/cctray.xml b/test/cctray.xml new file mode 100644 index 0000000..d02d228 --- /dev/null +++ b/test/cctray.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/test/fixtures/schedulers.yml b/test/fixtures/schedulers.yml new file mode 100644 index 0000000..5bf0293 --- /dev/null +++ b/test/fixtures/schedulers.yml @@ -0,0 +1,7 @@ +# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html + +# one: +# column: value +# +# two: +# column: value diff --git a/test/performance/browsing_test.rb b/test/performance/browsing_test.rb new file mode 100644 index 0000000..4b60558 --- /dev/null +++ b/test/performance/browsing_test.rb @@ -0,0 +1,9 @@ +require 'test_helper' +require 'performance_test_help' + +# Profiling results for each test method are written to tmp/performance. +class BrowsingTest < ActionController::PerformanceTest + def test_homepage + get '/' + end +end diff --git a/test/test_helper.rb b/test/test_helper.rb new file mode 100644 index 0000000..9f19269 --- /dev/null +++ b/test/test_helper.rb @@ -0,0 +1,38 @@ +ENV["RAILS_ENV"] = "test" +require File.expand_path(File.dirname(__FILE__) + "/../config/environment") +require 'test_help' + +class Test::Unit::TestCase + # Transactional fixtures accelerate your tests by wrapping each test method + # in a transaction that's rolled back on completion. This ensures that the + # test database remains unchanged so your fixtures don't have to be reloaded + # between every test method. Fewer database queries means faster tests. + # + # Read Mike Clark's excellent walkthrough at + # http://clarkware.com/cgi/blosxom/2005/10/24#Rails10FastTesting + # + # Every Active Record database supports transactions except MyISAM tables + # in MySQL. Turn off transactional fixtures in this case; however, if you + # don't care one way or the other, switching from MyISAM to InnoDB tables + # is recommended. + # + # The only drawback to using transactional fixtures is when you actually + # need to test transactions. Since your test is bracketed by a transaction, + # any transactions started in your code will be automatically rolled back. + self.use_transactional_fixtures = true + + # Instantiated fixtures are slow, but give you @david where otherwise you + # would need people(:david). If you don't want to migrate your existing + # test cases which use the @david style and don't mind the speed hit (each + # instantiated fixtures translates to a database query per test method), + # then set this back to true. + self.use_instantiated_fixtures = false + + # Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order. + # + # Note: You'll currently still have to declare fixtures explicitly in integration tests + # -- they do not yet inherit this setting + fixtures :all + + # Add more helper methods to be used by all tests here... +end