Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flag broken updater on every refresh attempt #150

Merged
merged 3 commits into from
Jul 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions src/howitz/endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
from datetime import datetime, timezone, timedelta

from werkzeug.exceptions import BadRequest, InternalServerError, MethodNotAllowed
from zinolib.controllers.zino1 import Zino1EventManager, RetryError, EventClosedError, UpdateHandler, LostConnectionError
from zinolib.controllers.zino1 import Zino1EventManager, UpdateHandler
from zinolib.controllers.zino1 import RetryError, EventClosedError, LostConnectionError, NotConnectedError
from zinolib.event_types import Event, AdmState, PortState, BFDState, ReachabilityState, LogEntry, HistoryEntry
from zinolib.compat import StrEnum
from zinolib.ritz import AuthenticationError
Expand Down Expand Up @@ -131,9 +132,9 @@ def connect_to_updatehandler():
if current_app.event_manager.is_authenticated: # is zino authenticated
current_app.updater = UpdateHandler(current_app.event_manager, autoremove=current_app.zino_config.autoremove)
current_app.updater.connect()
current_app.logger.debug('UpdateHandler %s', current_app.updater)
return True
return False
current_app.logger.debug('Connected to UpdateHandler: %s', current_app.updater)
return
raise NotConnectedError('Session not authenticated, cannot connect to UpdateHandler')
hmpf marked this conversation as resolved.
Show resolved Hide resolved


def connect_to_zino(username, token):
hmpf marked this conversation as resolved.
Show resolved Hide resolved
Expand Down Expand Up @@ -196,10 +197,13 @@ def get_sorted_table_event_list(events: dict):

def update_events():
updated_ids = set()
if current_app.updater is None:
return updated_ids

while True:
if current_app.updater is None:
try:
connect_to_updatehandler()
except NotConnectedError as e:
raise LostConnectionError("Could not establish connection to UpdateHandler") from e
updated = current_app.updater.get_event_update()
Comment on lines 201 to 207
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
while True:
if current_app.updater is None:
try:
connect_to_updatehandler()
except NotConnectedError as e:
raise LostConnectionError("Could not establish connection to UpdateHandler") from e
updated = current_app.updater.get_event_update()
while True:
if current_app.updater is None:
try:
connect_to_updatehandler()
except NotConnectedError as e:
raise LostConnectionError("Could not establish connection to UpdateHandler") from e
updated = current_app.updater.get_event_update()

Is there a specific reason why current_app.updater is None-check should be run on every iteration? Could be moved to before the while-loop instead

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It used to be before the while loop but that was not sufficient, the connection can be lost during the loop!

if not updated:
break
Expand All @@ -210,9 +214,10 @@ def update_events():

def refresh_current_events():
if current_app.updater is None:
updates_ok = connect_to_updatehandler()
if not updates_ok:
raise LostConnectionError("Could not establish connection to UpdateHandler")
try:
connect_to_updatehandler()
except NotConnectedError as e:
raise LostConnectionError("Could not establish connection to UpdateHandler") from e

event_ids = update_events()
current_app.logger.debug('UPDATED EVENT IDS %s', event_ids)
Expand Down