Class: CiLite::Runner
- Inherits:
-
Object
- Object
- CiLite::Runner
- Defined in:
- lib/cilite/runner.rb
Instance Attribute Summary collapse
-
#branch ⇒ Object
readonly
Returns the value of attribute branch.
-
#command ⇒ Object
readonly
Returns the value of attribute command.
-
#interval ⇒ Object
readonly
Returns the value of attribute interval.
-
#started ⇒ Object
Returns the value of attribute started.
Class Method Summary collapse
Instance Method Summary collapse
- #git_update ⇒ Object
-
#initialize(options) ⇒ Runner
constructor
A new instance of Runner.
- #output_result(hash, build) ⇒ Object
- #start ⇒ Object
- #test(hash) ⇒ Object
- #test_if_updated ⇒ Object
Constructor Details
#initialize(options) ⇒ Runner
Returns a new instance of Runner.
10 11 12 13 14 15 |
# File 'lib/cilite/runner.rb', line 10 def initialize() = (KVS['config'] || {}).merge() @branch = [:branch] @command = [:command] @interval = [:interval] end |
Instance Attribute Details
#branch ⇒ Object (readonly)
Returns the value of attribute branch.
7 8 9 |
# File 'lib/cilite/runner.rb', line 7 def branch @branch end |
#command ⇒ Object (readonly)
Returns the value of attribute command.
7 8 9 |
# File 'lib/cilite/runner.rb', line 7 def command @command end |
#interval ⇒ Object (readonly)
Returns the value of attribute interval.
7 8 9 |
# File 'lib/cilite/runner.rb', line 7 def interval @interval end |
#started ⇒ Object
Returns the value of attribute started.
8 9 10 |
# File 'lib/cilite/runner.rb', line 8 def started @started end |
Class Method Details
.start(options) ⇒ Object
3 4 5 |
# File 'lib/cilite/runner.rb', line 3 def self.start() self.new().start end |
Instance Method Details
#git_update ⇒ Object
40 41 42 43 44 45 46 47 48 |
# File 'lib/cilite/runner.rb', line 40 def git_update if system("git fetch origin && git reset --hard origin/#{branch}") hash = `git rev-parse origin/#{branch}`.chomp raise "failed to get HEAD commit of origin/#{branch}" unless $? == 0 hash else raise "failed to update origin/#{branch}" end end |
#output_result(hash, build) ⇒ Object
64 65 66 67 68 69 70 71 |
# File 'lib/cilite/runner.rb', line 64 def output_result(hash, build) puts build.output if build.success? puts "<green>[Success!] #{hash}</green>".termcolor else puts "<red>[Failure!] #{hash}</red>".termcolor end end |
#start ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/cilite/runner.rb', line 17 def start return if started Thread.start do loop do begin test_if_updated rescue Exception => e puts "<red>#{TermColor.escape(e.to_s)}</red>".termcolor ensure sleep interval end end end self.started = true end |
#test(hash) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/cilite/runner.rb', line 50 def test(hash) puts "start: #{hash}", command build = Build.new(command) build.start Log[hash] = build.to_hash.merge( :hash => hash, :created_at => Time.now, :branch => branch ) output_result(hash, build) end |
#test_if_updated ⇒ Object
33 34 35 36 37 38 |
# File 'lib/cilite/runner.rb', line 33 def test_if_updated hash = git_update unless KVS[hash] test(hash) end end |