On Sat, 21 Feb 2009 22:09:32 -0700
Chad Woolley <[email protected]> wrote:

> On Sat, Feb 21, 2009 at 12:32 PM, Alexey Verkhovsky
> <[email protected]> wrote:
> > On Sat, Feb 21, 2009 at 10:35 AM, Sebastian Nowak
> > <[email protected]> wrote:
> >>
> >> Hello,
> >> I wonder if there is possible to do something like this:
> >> - on every commit CC execute rake test
> >> - once a day CC execute rake test:coverage
> >
> > This sounds like a piece of logic that you can easily implement
> > within the Rake build.
> >
> > The idea with CC.rb is that it doesn't provide unusual fancy
> > features - if you need them, you either put it in the build or hack
> > the tool itself. It's rather simple, and written in an interpreted
> > language. Therefore, easy to hack.
> 
> I looked at the source briefly.  You'd have to make a custom trigger
> that ran only periodically, I think?
> 
> Does anyone have code to do this?  I think Jeremy mentioned it once...

I had a similiar need and created my own scheduler using
rufus/scheduler.  I did setup a separate project for the full rebuild
which uses this scheduler:

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
# Project-specific configuration for CruiseControl.rb

Struct.new( "RebuildDef", :cronline, :type )  #type = :full or :quick

Project.configure do |project|
  
  # // Build the project by invoking rake task 'custom' _OR_ by invoking shell 
script
  project.rake_task = 'cruise'
  
  build_defs = [ Struct::RebuildDef.new( '0 12 * * 1-6', :quick ), 
                 Struct::RebuildDef.new( '0 23 * * 1-6', :quick ), 
                 Struct::RebuildDef.new( '0 12 * * 0',   :full  )  ]
                         
  project.scheduler = CronScheduler.new( project, build_defs )

end
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 



cruisecontrol/lib/builder_plugins/cron_scheduler.rb
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
require 'rubygems'
require 'rufus/scheduler'

class CronScheduler

  def initialize(project, build_defs)
    @project = project
    @last_build_loop_error_source = nil
    @last_build_loop_error_time = nil
    
    @build_defs = build_defs
  end

  def run
    scheduler = Rufus::Scheduler.new()
    scheduler.start
    
    @build_defs.each do |build_def|
      puts "Creating cron job #{build_def.cronline} #{build_def.type}..."
      scheduler.schedule(build_def.cronline) do 
        puts "Job #{build_def.cronline} #{build_def.type} running..."
        begin
          ENV['CC_BUILD_TYPE'] = "#{build_def.type}"
          case build_def.type
          when :quick  # Quick build if new revision available or build 
requested
            @project.build_if_necessary
          when :full   # Compulsory full rebuild 
            @project.remove_build_requested_flag_file if 
@project.build_requested?
            @project.build(@project.source_control.latest_revision, ['Scheduled 
full rebuild'])
          end
          clean_last_build_loop_error
          throw :reload_project if @project.config_modified?
        rescue => e
          log_error(e) unless (same_error_as_before(e) and 
last_logged_less_than_an_hour_ago)
        end
      end
    end

    scheduler.join    
  end
  
  def same_error_as_before(error)
    @last_build_loop_error_source and (error.backtrace.first == 
@last_build_loop_error_source)
  end
  
  def last_logged_less_than_an_hour_ago
    @last_build_loop_error_time and @last_build_loop_error_time >= 1.hour.ago
  end
  
  def log_error(error)
    begin
      CruiseControl::Log.error(error) 
    rescue 
      STDERR.puts(error.message)
      STDERR.puts(error.backtrace.map { |l| "  #{l}"}.join("\n"))
    end
    @last_build_loop_error_source = error.backtrace.first
    @last_build_loop_error_time = Time.now
  end

  def clean_last_build_loop_error
    @last_build_loop_error_source = @last_build_loop_error_time = nil
  end
  
end

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 





_______________________________________________
Cruisecontrolrb-users mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/cruisecontrolrb-users

Reply via email to