Class: Juici::Build

Inherits:
Object
  • Object
show all
Includes:
BuildLogic, Mongoid::Document
Defined in:
lib/juici/models/build.rb

Instance Method Summary collapse

Methods included from BuildLogic

#spawn_build

Instance Method Details

#build!Object



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/juici/models/build.rb', line 62

def build!
  case pid = spawn_build
  when Fixnum
    start!
    Juici.dbgp "#{pid} away!"
    self[:pid] = pid
    self[:buffer] = @buffer.path
    save!
    return pid
  when :enoent
    warn! "No such command"
    failure!
  when :invalidcommand
    warn! "Invalid command"
    failure!
  end
  nil
end

#display_titleObject



107
108
109
110
# File 'lib/juici/models/build.rb', line 107

def display_title
  # Catch old builds which didn't have a title
  self[:title] || self[:create_time]
end

#failure!Object



50
51
52
53
54
# File 'lib/juici/models/build.rb', line 50

def failure!
  finish
  set_status :failed
  process_callbacks
end

#finishObject



56
57
58
59
60
# File 'lib/juici/models/build.rb', line 56

def finish
  self[:end_time] = Time.now
  self[:output] = get_output
  $build_queue.purge(:pid, self)
end

#get_outputObject



99
100
101
102
103
104
105
# File 'lib/juici/models/build.rb', line 99

def get_output
  return "" unless self[:buffer]
  File.open(self[:buffer], 'r') do |f|
    f.rewind
    f.read
  end
end

#heading_colorObject

View helpers



86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/juici/models/build.rb', line 86

def heading_color
  case status
  when :waiting
    "build-heading-pending"
  when :failed
    "build-heading-failed"
  when :success
    "build-heading-success"
  when :started
    "build-heading-started"
  end
end

#process_callbacksObject



117
118
119
120
121
# File 'lib/juici/models/build.rb', line 117

def process_callbacks
  self[:callbacks].each do |callback_url|
    Callback.new(self, callback_url).process!
  end
end

#set_status(value) ⇒ Object



34
35
36
37
# File 'lib/juici/models/build.rb', line 34

def set_status(value)
  self[:status] = value
  save!
end

#start!Object



39
40
41
42
# File 'lib/juici/models/build.rb', line 39

def start!
  self[:start_time] = Time.now
  set_status :started
end

#success!Object



44
45
46
47
48
# File 'lib/juici/models/build.rb', line 44

def success!
  finish
  set_status :success
  process_callbacks
end

#to_callback_jsonObject



124
125
126
127
128
129
130
# File 'lib/juici/models/build.rb', line 124

def to_callback_json
  {
    "project" => self[:parent],
    "status" => self[:status],
    "url" => build_url_for(self)
  }.to_json
end

#warn!(msg) ⇒ Object



112
113
114
115
# File 'lib/juici/models/build.rb', line 112

def warn!(msg)
  warnings << msg
  save!
end

#worktreeObject



81
82
83
# File 'lib/juici/models/build.rb', line 81

def worktree
  File.join(Config.workspace, parent)
end