Add healthcheck support
This commit is contained in:
parent
c14b8bb1cf
commit
b831b82458
1 changed files with 30 additions and 2 deletions
32
scl.py
32
scl.py
|
@ -17,6 +17,7 @@ from sqlalchemy.orm import DeclarativeBase, Mapped, Session, mapped_column
|
|||
|
||||
from geospatial import DBGeometry, convert_outage_geometry
|
||||
|
||||
REQUESTS_HEADERS = {"User-Agent": "seattlecitylight-mastodon-bot"}
|
||||
post_datetime_format = "%b %e %l:%M %p"
|
||||
|
||||
scl_events_url = "https://utilisocial.io/datacapable/v2/p/scl/map/events"
|
||||
|
@ -38,6 +39,34 @@ mastodon_client = Mastodon(
|
|||
api_base_url=config["mastodon"]["api_base_url"],
|
||||
)
|
||||
|
||||
try:
|
||||
mastodon_client.account_verify_credentials()
|
||||
except Exception:
|
||||
print("Mastodon health check failed")
|
||||
raise
|
||||
|
||||
if config["nominatim"]["health_check_url"]:
|
||||
try:
|
||||
health_check_response = requests.get(
|
||||
config["nominatim"]["health_check_url"],
|
||||
headers=REQUESTS_HEADERS,
|
||||
timeout=10,
|
||||
)
|
||||
assert health_check_response.ok
|
||||
except Exception:
|
||||
print("Nominatim health check failed")
|
||||
raise
|
||||
|
||||
if config["osm"]["health_check_url"]:
|
||||
try:
|
||||
health_check_response = requests.get(
|
||||
config["osm"]["health_check_url"], headers=REQUESTS_HEADERS, timeout=10
|
||||
)
|
||||
assert health_check_response.ok
|
||||
except Exception:
|
||||
print("OSM health check failed")
|
||||
raise
|
||||
|
||||
|
||||
class AttribStaticMap(staticmap.StaticMap, object):
|
||||
def __init__(self, *args, **kwargs):
|
||||
|
@ -168,8 +197,7 @@ def do_initial_post(
|
|||
lat=outage_center.y,
|
||||
lon=outage_center.x,
|
||||
)
|
||||
geocode_headers = {"User-Agent": "seattlecitylight-mastodon-bot"}
|
||||
geocode_response = requests.get(geocode_url, headers=geocode_headers)
|
||||
geocode_response = requests.get(geocode_url, headers=REQUESTS_HEADERS)
|
||||
try:
|
||||
geocode = geocode_response.json()
|
||||
except requests.JSONDecodeError:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue