Skip to content

Commit

Permalink
error status from health endpoint into function
Browse files Browse the repository at this point in the history
also fix to point to the correct key
  • Loading branch information
blankdots committed Feb 9, 2021
1 parent be16071 commit c1f1567
Showing 1 changed file with 20 additions and 28 deletions.
48 changes: 20 additions & 28 deletions swift_browser_ui/health.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@
from .signature import sign


def _set_error_status(
request: aiohttp.web.Request,
services: typing.Dict[str, typing.Any],
service: str,
)-> None:
request.app["Log"].debug(f"Poll {service} failed")
services[service] = {
"status": "Error"
}


async def get_x_account_sharing(
services: typing.Dict[str, typing.Any],
request: aiohttp.web.Request,
Expand Down Expand Up @@ -42,17 +53,10 @@ async def get_x_account_sharing(
"status": "Nonexistent"
}
except ServerDisconnectedError:
request.app["Log"].debug("Poll swift-x-account-sharing failed")
services["swift-x-account-sharing"] = {
"status": "Error"
}
_set_error_status(request, services, "swift-x-account-sharing")
except Exception as e:
request.app["Log"].debug("Poll swift-x-account-sharing failed")
request.app["Log"].info(f"reason: {e}")
services["swift-sharing-request"] = {
"status": "Error"
}

request.app["Log"].info(f"Health failed for reason: {e}")
_set_error_status(request, services, "swift-x-account-sharing")

async def get_swift_sharing(
services: typing.Dict[str, typing.Any],
Expand Down Expand Up @@ -85,16 +89,10 @@ async def get_swift_sharing(
"status": "Nonexistent"
}
except ServerDisconnectedError:
request.app["Log"].debug("Poll swift-x-account-sharing failed")
services["swift-sharing-request"] = {
"status": "Error"
}
_set_error_status(request, services, "swift-sharing-request")
except Exception as e:
request.app["Log"].debug("Poll swift-x-account-sharing failed")
request.app["Log"].info(f"reason: {e}")
services["swift-sharing-request"] = {
"status": "Error"
}
request.app["Log"].info(f"Health failed for reason: {e}")
_set_error_status(request, services, "swift-sharing-request")


async def get_upload_runner(
Expand Down Expand Up @@ -128,16 +126,10 @@ async def get_upload_runner(
"status": "Nonexistent"
}
except ServerDisconnectedError:
request.app["Log"].debug("Poll swift-x-account-sharing failed")
services["swiftui-upload-runner"] = {
"status": "Error"
}
_set_error_status(request, services, "swiftui-upload-runner")
except Exception as e:
request.app["Log"].debug("Poll swift-x-account-sharing failed")
request.app["Log"].info(f"reason: {e}")
services["swift-sharing-request"] = {
"status": "Error"
}
request.app["Log"].info(f"Health failed for reason: {e}")
_set_error_status(request, services, "sswiftui-upload-runner")


async def handle_health_check(
Expand Down

0 comments on commit c1f1567

Please sign in to comment.