Permalink
Browse files

Allow project level timeouts for git commands.

Specified via the `timeout` option per project. Any failure (raised exception) that occurs during the deployment (clone, checkout, run) is caught, logged, and the deployment directory is cleaned up.
  • Loading branch information...
dreverri committed Oct 7, 2011
1 parent 742df81 commit 5fb8bc91ffe5bb372798bc6bb5dc06b91228156b
Showing with 9 additions and 6 deletions.
  1. +7 −5 lib/github_post_receive/deployment.rb
  2. +2 −1 lib/github_post_receive/project.rb
@@ -16,14 +16,16 @@ def initialize(project, remote, commit_id)
end
def clone
+ options = {:raise => true, :timeout => @project.timeout}
App.logger.debug "Adding #{@remote} as 'origin'"
- @repo.remote_add('origin', @remote)
+ @repo.git.remote(options, 'add', 'origin', @remote)
App.logger.debug "Fetching #{@remote}"
- @repo.remote_fetch('origin')
+ @repo.git.fetch(options, 'origin')
end
def checkout
@repo.git.checkout({:raise => true,
+ :timeout => @project.timeout,
:base => false,
:chdir => @repo.working_dir}, @commit_id)
end
@@ -33,15 +35,15 @@ def run
process = Child.new(@project.cmd, :chdir => @repo.working_dir)
raise process.err unless process.status.success?
return true
- rescue => e
- App.logger.error "Project command (#{@project.cmd}) failed: #{e.message}"
- return false
end
def deploy
clone
checkout
run
+ rescue => e
+ App.logger.error "Deploy failed [#{@project.name}][#{@project.path}][#{@commit_id}]: #{e.inspect}"
+ return false
end
end
end
@@ -1,13 +1,14 @@
module GithubPostReceive
class Project
- attr_reader :path, :name, :branch, :cmd, :token
+ attr_reader :path, :name, :branch, :cmd, :token, :timeout
def initialize(path, options = {})
@path = path
@name = options['name']
@branch = options['branch']
@cmd = options['cmd']
@token = options['token']
+ @timeout = options['timeout'] || false
end
def match?(payload)

0 comments on commit 5fb8bc9

Please sign in to comment.