public
Description: CruiseControl.rb is a continuous integration tool, written in Ruby. It is quick to install, simple to use and easy to hack.
Homepage: http://cruisecontrolrb.thoughtworks.com/
Clone URL: git://github.com/benburkert/cruisecontrolrb.git
Scott Steadman (author)
Wed Jul 23 09:05:30 -0700 2008
commit  b92a33a4436fb62aab4f9b6e6e5533d8dbf8e079
tree    18f3b5b63977565abbf8e23e45ac3a68c5f0b561
parent  ac1fcf5414d877e86b7cded02f089a0ed68ce7ba
cruisecontrolrb / lib / build_serializer.rb
100644 41 lines (35 sloc) 0.875 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
class BuildSerializer
  include ActionView::Helpers::DateHelper
  
  def self.serialize(project, &block)
    BuildSerializer.new(project).serialize(&block)
  end
  
  def initialize(project)
    @project = project
  end
  
  def serialize
    @start_time = Time.now
    lock = FileLock.new(CRUISE_DATA_ROOT + "/projects/build_serialization.lock")
    begin
      lock.lock
    rescue FileLock::LockUnavailableError
      unless @already_told
        @project.notify(:queued)
        @already_told = true
      end
      wait
      timeout or retry
    end
 
    yield
  ensure
    lock.release
  end
  
  def timeout
    if Time.now - @start_time >= Configuration.serialized_build_timeout
      @project.notify(:timed_out)
      raise "Timed out after waiting to build for #{distance_of_time_in_words(@start_time, Time.now)}"
    end
  end
  
  def wait
    sleep 5
  end
end