Skip to content

Commit

Permalink
Better error handling w/ chronos-sync.rb.
Browse files Browse the repository at this point in the history
  • Loading branch information
Brenden Matthews committed Mar 13, 2014
1 parent 41f2f9c commit a0d978f
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions bin/chronos-sync.rb
Original file line number Diff line number Diff line change
Expand Up @@ -259,17 +259,20 @@ def write_job(f, job)

puts "Sending PUT for `#{job['name']}` to #{uri.request_uri}"

res = Net::HTTP.start(uri.hostname, port: uri.port, use_ssl: (uri.port == 443)) do |http|
http.request(req)
end
begin
res = Net::HTTP.start(uri.hostname, port: uri.port, use_ssl: (uri.port == 443)) do |http|
http.request(req)
end

case res
when Net::HTTPSuccess, Net::HTTPRedirection
# OK
else
$stderr.puts "Error updating job #{job['name']}!"
$stderr.puts res.value
end
case res
when Net::HTTPSuccess, Net::HTTPRedirection
# OK
end
rescue Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, EOFError,
Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError => e
$stderr.puts "Error updating job #{job['name']}!"
$stderr.puts res.value
end

# Pause after each request so we don't explode chronos
sleep 0.1
Expand Down

0 comments on commit a0d978f

Please sign in to comment.