Skip to content

Commit

Permalink
Use ConsulException in keep_alive method.
Browse files Browse the repository at this point in the history
* there was a change and now they python-consul raises exception instead
of `False`
  • Loading branch information
Tomasz Święcicki authored and tomislater committed Jul 10, 2017
1 parent 3996b44 commit 152fbbe
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
7 changes: 4 additions & 3 deletions src/ianitor/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
import logging
from requests import ConnectionError

from consul import Check

from consul import Check, ConsulException

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -122,7 +121,9 @@ def keep_alive(self):
:return: None
"""
with ignore_connection_errors("ttl_pass"):
if not self.session.agent.check.ttl_pass(self.check_id):
try:
self.session.agent.check.ttl_pass(self.check_id)
except ConsulException:
# register and ttl_pass again if it failed
logger.warning("service keep-alive failed, re-registering")
self.register()
Expand Down
3 changes: 1 addition & 2 deletions tests/test_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def test_remove_services():
if description["ID"] != 'consul':
agent.service.deregister(description["ID"])

# this is consul 0.4.1 behavior - consul is one of services
# this is consul behavior - consul is one of services
services = agent.services()
if 'consul' in services:
services.pop('consul')
Expand Down Expand Up @@ -142,7 +142,6 @@ def _get_service_status(session, service_obj):
# return none because check does not even exist
return

# from pprint import pprint; pprint(checks)
service_check = list(filter(
lambda check: check["ServiceName"] == service_obj.service_name, checks
)).pop()
Expand Down

0 comments on commit 152fbbe

Please sign in to comment.