Skip to content
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
59 changes: 32 additions & 27 deletions lib/dt_shell/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,35 +100,41 @@ def __init__(self, shell, **kwargs):
def execute(self):
url: str = f"{DTHUB_URL}/api/v1/billboard/list/"
raw: Optional[Response] = None
bboards: list[dict] = []
# reach out to the HUB and grab the new billboards
try:
logger.debug(f"GET {url}")
raw = requests.get(url)
response: dict = raw.json()
self._shell.profile.events.new("shell/billboards/update")
except JSONDecodeError:
logger.warning("An error occurred while decoding the received billboards. Use --verbose for further info")
logger.debug(traceback.format_exc())
logger.debug("HUB response:\n" + str(raw))
# mark as updated so we don't retry right away
self._shell.mark_updated("billboards")
return
except Exception:
logger.warning("An error occurred while updating the billboards")
logger.debug(traceback.format_exc())
# mark as updated so we don't retry right away
self._shell.mark_updated("billboards")
return
# check response
if response.get("success", False) is not True:
logger.warning("An error occurred while updating the billboards")
logger.debug("HUB response:\n" + json.dumps(response, indent=4, sort_keys=True))
# mark as updated so we don't retry right away
self._shell.mark_updated("billboards")
return
while url:
try:
logger.debug(f"GET {url}")
raw = requests.get(url)
response: dict = raw.json()
self._shell.profile.events.new("shell/billboards/update")
except JSONDecodeError:
logger.warning("An error occurred while decoding the received billboards. Use --verbose for further info")
logger.debug(traceback.format_exc())
logger.debug("HUB response:\n" + str(raw))
# mark as updated so we don't retry right away
self._shell.mark_updated("billboards")
return
except Exception:
logger.warning("An error occurred while updating the billboards")
logger.debug(traceback.format_exc())
# mark as updated so we don't retry right away
self._shell.mark_updated("billboards")
return
# check response
if response.get("success", False) is not True:
logger.warning("An error occurred while updating the billboards")
logger.debug("HUB response:\n" + json.dumps(response, indent=4, sort_keys=True))
# mark as updated so we don't retry right away
self._shell.mark_updated("billboards")
return
result: dict = response.get("result", {})
results: list[dict] = result.get("results", [])
bboards.extend(results)
url = result.get("next", "")
# update local database
self._db.clear()
for bboard in response.get("result", {}).get("results", []):
for bboard in bboards:
self._db.set(bboard["name"], bboard)
self._shell.mark_updated("billboards")
logger.debug("Billboards updated!")
Expand Down Expand Up @@ -204,4 +210,3 @@ def execute(self):

def shutdown(self, event: Event):
pass