Skip to content
This repository has been archived by the owner on Dec 5, 2019. It is now read-only.

Commit

Permalink
add always_build flag to PollingScheduler to allow forcing of builds …
Browse files Browse the repository at this point in the history
…on a schedule even if there are no SCM changes
  • Loading branch information
thewoolleyman committed Jan 12, 2010
1 parent 88d4b65 commit 0cd553f
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 1 deletion.
7 changes: 6 additions & 1 deletion app/models/polling_scheduler.rb
@@ -1,6 +1,7 @@
# PollingScheduler is a build scheduler that checks the given project's status one per polling
# interval to determine whether or not it should kick off a new build.
class PollingScheduler
attr_accessor :always_build

def initialize(project)
@project = project
Expand All @@ -25,7 +26,11 @@ def run
def check_build_request_until_next_polling
time_to_go = Time.now + polling_interval
while Time.now < time_to_go
@project.build_if_requested
if @always_build
@project.force_build("Forcing build because project has 'always_build' flag set.")
else
@project.build_if_requested
end
sleep build_request_checking_interval
end
end
Expand Down
4 changes: 4 additions & 0 deletions app/models/project.rb
Expand Up @@ -326,6 +326,10 @@ def build_if_requested
end
end

def force_build(message = 'Build was forced')
build(source_control.latest_revision, [message, source_control.latest_revision.to_s])
end

def update_project_to_revision(build, revision)
if do_clean_checkout?
File.open(build.artifact('source_control.log'), 'w') do |f|
Expand Down
4 changes: 4 additions & 0 deletions config/cruise_config.rb.example
Expand Up @@ -19,4 +19,8 @@ Project.configure do |project|
# Ping Subversion for new revisions every 5 minutes (default: 30 seconds)
# project.scheduler.polling_interval = 5.minutes

# Force the project always build once every day
# project.scheduler.polling_interval = 1.day
# project.scheduler.always_build = true

end
12 changes: 12 additions & 0 deletions test/unit/polling_scheduler_test.rb
Expand Up @@ -54,4 +54,16 @@ def test_should_return_flag_to_reload_project_if_configurations_modified

assert_throws(:reload_project) { @scheduler.run }
end

def test_should_always_build_if_always_build_is_set
@scheduler.expects(:polling_interval).returns(1.seconds)
@scheduler.stubs(:build_request_checking_interval).returns(0)
Time.expects(:now).times(3).returns(Time.at(0), Time.at(0), Time.at(2))

@mock_project.expects(:build_if_requested).times(0)
@mock_project.expects(:force_build).times(1)

@scheduler.always_build = true
@scheduler.check_build_request_until_next_polling
end
end
9 changes: 9 additions & 0 deletions test/unit/project_test.rb
Expand Up @@ -424,6 +424,15 @@ def test_build_if_requested_should_specify_build_requested_reason
end
end

def test_force_build
in_sandbox do |sandbox|
@project.path = sandbox.root
revision = @project.source_control.add_revision :message => "A super special feature", :number => 1
@project.expects(:build).with(revision, ['Custom message.', '1: A super special feature'])
@project.force_build('Custom message.')
end
end

def test_build_requested
@project.stubs(:path).returns("a_path")
File.expects(:file?).with(@project.build_requested_flag_file).returns(true)
Expand Down

0 comments on commit 0cd553f

Please sign in to comment.