Class: Cerberus::BuildCommand
- Inherits:
-
Object
- Object
- Cerberus::BuildCommand
- Defined in:
- lib/cerberus/manager.rb
Constant Summary collapse
- DEFAULT_CONFIG =
{:scm => {:type => 'svn'}, :log => {:enable => true}, :at_time => '* *', :max_wait_time => LOCK_WAIT, :require_revision_change => false }
Instance Attribute Summary collapse
-
#builder ⇒ Object
readonly
Returns the value of attribute builder.
-
#scm ⇒ Object
readonly
Returns the value of attribute scm.
-
#setup_script_output ⇒ Object
readonly
Returns the value of attribute setup_script_output.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
-
#success ⇒ Object
readonly
Returns the value of attribute success.
Instance Method Summary collapse
-
#initialize(application_name, cli_options = {}) ⇒ BuildCommand
constructor
A new instance of BuildCommand.
- #run ⇒ Object
- #run_time?(time) ⇒ Boolean
Constructor Details
#initialize(application_name, cli_options = {}) ⇒ BuildCommand
Returns a new instance of BuildCommand.
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/cerberus/manager.rb', line 92 def initialize(application_name, = {}) unless File.exists?("#{HOME}/config/#{application_name}.yml") say "Project '#{application_name}' does not exist in Cerberus. Type 'cerberus list' to see the list of all active projects." end app_root = "#{HOME}/work/#{application_name}" = {:application_root => app_root + '/sources', :application_name => application_name} #pseudo options that stored in config. Could not be set in any config file not through CLI @config = Config.new(application_name, .merge()) @config.merge!(DEFAULT_CONFIG, false) @status = Status.read("#{app_root}/status.log") scm_type = @config[:scm, :type] @scm = SCM.get(scm_type).new(@config[:application_root], @config) say "Client for SCM '#{scm_type}' does not installed" unless @scm.installed? builder_type = get_configuration_option(@config[:builder], :type, :rake) @builder = Builder.get(builder_type).new(@config) end |
Instance Attribute Details
#builder ⇒ Object (readonly)
Returns the value of attribute builder.
83 84 85 |
# File 'lib/cerberus/manager.rb', line 83 def builder @builder end |
#scm ⇒ Object (readonly)
Returns the value of attribute scm.
83 84 85 |
# File 'lib/cerberus/manager.rb', line 83 def scm @scm end |
#setup_script_output ⇒ Object (readonly)
Returns the value of attribute setup_script_output.
83 84 85 |
# File 'lib/cerberus/manager.rb', line 83 def setup_script_output @setup_script_output end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
83 84 85 |
# File 'lib/cerberus/manager.rb', line 83 def status @status end |
#success ⇒ Object (readonly)
Returns the value of attribute success.
83 84 85 |
# File 'lib/cerberus/manager.rb', line 83 def success @success end |
Instance Method Details
#run ⇒ Object
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
# File 'lib/cerberus/manager.rb', line 113 def run begin Latch.lock("#{HOME}/work/#{@config[:application_name]}/.lock", :lock_ttl => @config[:max_wait_time]) do @scm.update! if ( @config[:force] || @scm.has_changes? || ( @status.previous_build_failed? && !@config[:require_revision_change] ) ) Dir.chdir File.join(@config[:application_root], @config[:build_dir] || '') @setup_script_output = `#{@config[:setup_script]}` if @config[:setup_script] build_successful = @builder.run @status.keep(build_successful, @scm.current_revision, @builder.brokeness) #Save logs to directory if @config[:log, :enable] log_dir = "#{HOME}/work/#{@config[:application_name]}/logs/" FileUtils.mkpath(log_dir) time = Time.now.strftime("%Y%m%d%H%M%S") file_name = "#{log_dir}/#{time}-#{@status.current_state.to_s}.log" body = [ @setup_script_output, scm., builder.output ].join("\n\n") IO.write(file_name, body) end #send notifications active_publishers = get_configuration_option(@config[:publisher], :active, 'mail') active_publishers.split(/\W+/).each do |pub| publisher_config = @config[:publisher, pub] raise "Publisher have no configuration: #{pub}" unless publisher_config events = interpret_state(publisher_config[:on_event] || @config[:publisher, :on_event] || 'default') Publisher.get(pub, publisher_config).publish(@status, self, @config) if events.include?(@status.current_state) end #Process hooks hooks = @config[:hook] hooks.each_pair{|name, hook| events = interpret_state(hook[:on_event] || 'all', false) if events.include?(@status.current_state) `#{hook[:action]}` end } if hooks end end #lock rescue Exception => e if ENV['CERBERUS_ENV'] == 'TEST' raise e else File.open("#{HOME}/error.log", File::WRONLY|File::APPEND|File::CREAT) do |f| f.puts Time.now.strftime("%a, %d %b %Y %H:%M:%S [#{@config[:application_name]}] -- #{e.class}") f.puts e. unless e..empty? f.puts e.backtrace.collect{|line| ' '*5 + line} f.puts "\n" end end end end |
#run_time?(time) ⇒ Boolean
171 172 173 174 175 176 177 178 |
# File 'lib/cerberus/manager.rb', line 171 def run_time?(time) minute, hour = @config[:at_time].split say "Run time is configured wrong." if minute.nil? or hour.nil? if hour.cron_match?(time.hour) return minute.cron_match?(time.min) end return false end |