Skip to content

Commit

Permalink
don't kill monitor on an api error, improves #126
Browse files Browse the repository at this point in the history
  • Loading branch information
rkh committed Nov 4, 2013
1 parent 6b9a961 commit f0a287b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1448,6 +1448,7 @@ If you have the old `travis-cli` gem installed, you should `gem uninstall travis
* Add `travis cache` to list and delete directory caches.
* Add `travis report` to give a report of the system, endpoint, configuration and last exception.
* Add `Cache` entity.
* Keep `travis monitor` running on API errors.

**1.5.8** (October 24, 2013)

Expand Down
29 changes: 18 additions & 11 deletions lib/travis/cli/monitor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,20 +72,27 @@ def monitor?(entity)
entity.pull_request? ? pull? : push?
end

def display(entity, time)
say [
color(formatter.time(time), entity.color),
color(entity.inspect_info, [entity.color, :bold]),
color(entity.state, entity.color)
].join(" ")
notification.notify(entity.repository.slug, "#{entity.class.name[/[^:]+$/]} ##{entity.number} #{entity.state}")
end

def handle_event(event)
entity = event.job || event.build
time = entity.finished_at || entity.started_at
display(entity, time) if monitor? entity
rescue Travis::Client::Error => error
raise error if explode?
end

def run
listen(*repos) do |listener|
listener.on_connect { say description, "Monitoring #{"builds for " if builds?}%s:" }
listener.on(*events) do |event|
entity = event.job || event.build
time = entity.finished_at || entity.started_at
next unless monitor? entity
say [
color(formatter.time(time), entity.color),
color(entity.inspect_info, [entity.color, :bold]),
color(entity.state, entity.color)
].join(" ")
notification.notify(entity.repository.slug, "#{entity.class.name[/[^:]+$/]} ##{entity.number} #{entity.state}")
end
listener.on(*events) { |e| handle_event(e) }
end
end
end
Expand Down

0 comments on commit f0a287b

Please sign in to comment.