Skip to content

Commit

Permalink
Update to more modern tornado asyncio wait syntax (#275)
Browse files Browse the repository at this point in the history
* Update to more modern tornado asyncio wait syntax, fixing not responding server
  • Loading branch information
dsschult authored Feb 24, 2024
1 parent 7c5cd53 commit 42b64d4
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 121 deletions.
3 changes: 1 addition & 2 deletions docker-deps-down.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# docker-deps-down.sh
# Stop the docker containers that provide dev/test dependencies

docker stop test-lta-mongo
# docker stop test-lta-token
# docker stop test-lta-rest
15 changes: 4 additions & 11 deletions docker-deps-up.sh
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
# docker-deps-up.sh
# Run some docker containers to provide dev/test dependencies

docker pull circleci/mongo:latest-ram

docker run \
--detach \
--name test-lta-mongo \
--network=host \
--rm \
circleci/mongo:latest-ram &

# docker run \
# --env LTA_AUTH_AUDIENCE='lta' \
# --env LTA_AUTH_OPENID_URL='' \
# --env OTEL_EXPORTER_OTLP_ENDPOINT='localhost:4318' \
# --env WIPACTEL_EXPORT_STDOUT='FALSE' \
# --name test-lta-rest \
# --network=host \
# --rm \
# wipac/lta:latest python3 -m lta.rest_server &
circleci/mongo:latest-ram
15 changes: 4 additions & 11 deletions lta/rest_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
import logging
import os
import sys
from typing import Any, Callable, cast, Dict, Optional
from typing import Any, cast, Dict, Optional
from urllib.parse import quote_plus
from uuid import uuid1

from motor.motor_tornado import MotorClient, MotorDatabase # type: ignore
from motor.motor_tornado import MotorClient, MotorDatabase
from prometheus_client import Counter, start_http_server
import pymongo
from pymongo import MongoClient
Expand Down Expand Up @@ -817,13 +817,6 @@ def start(debug: bool = False) -> RestServer:


async def main() -> None:
"""Just loop forever while the REST server processes requests."""
while True:
LOG.info("Sleeping for 60 seconds")
await asyncio.sleep(60)


def main_sync() -> None:
"""Configure logging and start a LTA DB service."""
# obtain our configuration from the environment
config = from_environment(EXPECTED_CONFIG)
Expand All @@ -838,8 +831,8 @@ def main_sync() -> None:
start(debug=True)
metrics_port = int(config["PROMETHEUS_METRICS_PORT"])
start_http_server(metrics_port)
asyncio.run(main())
await asyncio.Event().wait()


if __name__ == '__main__':
main_sync()
asyncio.run(main())
58 changes: 26 additions & 32 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,11 @@
#
# pip-compile --extra=dev --output-file=requirements-dev.txt
#
backoff==2.2.1
# via
# opentelemetry-exporter-otlp-proto-common
# opentelemetry-exporter-otlp-proto-http
binpacking==1.5.2
# via lta (setup.py)
cachetools==5.3.2
# via wipac-rest-tools
certifi==2023.11.17
certifi==2024.2.2
# via requests
cffi==1.16.0
# via cryptography
Expand All @@ -30,31 +26,29 @@ colorama==0.4.6
# lta (setup.py)
coloredlogs==15.0.1
# via wipac-telemetry
coverage[toml]==7.4.0
# via
# coverage
# pytest-cov
coverage[toml]==7.4.3
# via pytest-cov
crayons==0.4.0
# via pycycle
cryptography==41.0.7
cryptography==42.0.5
# via pyjwt
deprecated==1.2.14
# via
# opentelemetry-api
# opentelemetry-exporter-otlp-proto-http
dnspython==2.4.2
dnspython==2.6.1
# via pymongo
exceptiongroup==1.2.0
# via pytest
flake8==7.0.0
# via lta (setup.py)
future==0.18.3
future==1.0.0
# via binpacking
googleapis-common-protos==1.59.1
# via
# opentelemetry-exporter-jaeger-proto-grpc
# opentelemetry-exporter-otlp-proto-http
grpcio==1.60.0
grpcio==1.62.0
# via opentelemetry-exporter-jaeger-proto-grpc
humanfriendly==10.0
# via coloredlogs
Expand All @@ -68,7 +62,7 @@ iniconfig==2.0.0
# via pytest
jinja2==3.1.3
# via click-completion
markupsafe==2.1.3
markupsafe==2.1.5
# via jinja2
mccabe==0.7.0
# via flake8
Expand All @@ -78,7 +72,7 @@ mypy==1.8.0
# via lta (setup.py)
mypy-extensions==1.0.0
# via mypy
opentelemetry-api==1.22.0
opentelemetry-api==1.23.0
# via
# opentelemetry-exporter-jaeger-proto-grpc
# opentelemetry-exporter-jaeger-thrift
Expand All @@ -91,29 +85,29 @@ opentelemetry-exporter-jaeger-proto-grpc==1.21.0
# via opentelemetry-exporter-jaeger
opentelemetry-exporter-jaeger-thrift==1.21.0
# via opentelemetry-exporter-jaeger
opentelemetry-exporter-otlp-proto-common==1.22.0
opentelemetry-exporter-otlp-proto-common==1.23.0
# via opentelemetry-exporter-otlp-proto-http
opentelemetry-exporter-otlp-proto-http==1.22.0
opentelemetry-exporter-otlp-proto-http==1.23.0
# via wipac-telemetry
opentelemetry-proto==1.22.0
opentelemetry-proto==1.23.0
# via
# opentelemetry-exporter-otlp-proto-common
# opentelemetry-exporter-otlp-proto-http
opentelemetry-sdk==1.22.0
opentelemetry-sdk==1.23.0
# via
# opentelemetry-exporter-jaeger-proto-grpc
# opentelemetry-exporter-jaeger-thrift
# opentelemetry-exporter-otlp-proto-http
# wipac-telemetry
opentelemetry-semantic-conventions==0.43b0
opentelemetry-semantic-conventions==0.44b0
# via opentelemetry-sdk
packaging==23.2
# via pytest
pluggy==1.3.0
pluggy==1.4.0
# via pytest
prometheus-client==0.19.0
prometheus-client==0.20.0
# via lta (setup.py)
protobuf==4.25.2
protobuf==4.25.3
# via
# googleapis-common-protos
# opentelemetry-proto
Expand All @@ -127,23 +121,21 @@ pycycle==0.0.8
pyflakes==3.2.0
# via flake8
pyjwt[crypto]==2.8.0
# via
# pyjwt
# wipac-rest-tools
pymongo==4.6.1
# via wipac-rest-tools
pymongo==4.6.2
# via
# lta (setup.py)
# motor
pypng==0.20220715.0
# via qrcode
pytest==7.4.4
pytest==8.0.1
# via
# lta (setup.py)
# pycycle
# pytest-asyncio
# pytest-cov
# pytest-mock
pytest-asyncio==0.23.3
pytest-asyncio==0.23.5
# via lta (setup.py)
pytest-cov==4.1.0
# via lta (setup.py)
Expand Down Expand Up @@ -177,7 +169,9 @@ tornado==6.4
# via
# lta (setup.py)
# wipac-rest-tools
types-requests==2.31.0.20240106
types-colorama==0.4.15.20240205
# via lta (setup.py)
types-requests==2.31.0.20240218
# via lta (setup.py)
typing-extensions==4.9.0
# via
Expand All @@ -186,12 +180,12 @@ typing-extensions==4.9.0
# qrcode
# wipac-dev-tools
# wipac-telemetry
urllib3==2.1.0
urllib3==2.2.1
# via
# requests
# types-requests
# wipac-rest-tools
wipac-dev-tools==1.8.2
wipac-dev-tools==1.9.1
# via
# lta (setup.py)
# wipac-rest-tools
Expand Down
48 changes: 20 additions & 28 deletions requirements-monitoring.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,19 @@
#
# pip-compile --extra=monitoring --output-file=requirements-monitoring.txt
#
aiohttp==3.9.1
aiohttp==3.9.3
# via elasticsearch
aiosignal==1.3.1
# via aiohttp
async-timeout==4.0.3
# via aiohttp
attrs==23.2.0
# via aiohttp
backoff==2.2.1
# via
# opentelemetry-exporter-otlp-proto-common
# opentelemetry-exporter-otlp-proto-http
binpacking==1.5.2
# via lta (setup.py)
cachetools==5.3.2
# via wipac-rest-tools
certifi==2023.11.17
certifi==2024.2.2
# via
# elasticsearch
# requests
Expand All @@ -32,29 +28,27 @@ colorama==0.4.6
# via lta (setup.py)
coloredlogs==15.0.1
# via wipac-telemetry
cryptography==41.0.7
cryptography==42.0.5
# via pyjwt
deprecated==1.2.14
# via
# opentelemetry-api
# opentelemetry-exporter-otlp-proto-http
dnspython==2.4.2
dnspython==2.6.1
# via pymongo
elasticsearch[async]==7.9.1
# via
# elasticsearch
# lta (setup.py)
# via lta (setup.py)
frozenlist==1.4.1
# via
# aiohttp
# aiosignal
future==0.18.3
future==1.0.0
# via binpacking
googleapis-common-protos==1.59.1
# via
# opentelemetry-exporter-jaeger-proto-grpc
# opentelemetry-exporter-otlp-proto-http
grpcio==1.60.0
grpcio==1.62.0
# via opentelemetry-exporter-jaeger-proto-grpc
humanfriendly==10.0
# via coloredlogs
Expand All @@ -68,11 +62,11 @@ importlib-metadata==6.11.0
# via opentelemetry-api
motor==3.3.2
# via lta (setup.py)
multidict==6.0.4
multidict==6.0.5
# via
# aiohttp
# yarl
opentelemetry-api==1.22.0
opentelemetry-api==1.23.0
# via
# opentelemetry-exporter-jaeger-proto-grpc
# opentelemetry-exporter-jaeger-thrift
Expand All @@ -85,36 +79,34 @@ opentelemetry-exporter-jaeger-proto-grpc==1.21.0
# via opentelemetry-exporter-jaeger
opentelemetry-exporter-jaeger-thrift==1.21.0
# via opentelemetry-exporter-jaeger
opentelemetry-exporter-otlp-proto-common==1.22.0
opentelemetry-exporter-otlp-proto-common==1.23.0
# via opentelemetry-exporter-otlp-proto-http
opentelemetry-exporter-otlp-proto-http==1.22.0
opentelemetry-exporter-otlp-proto-http==1.23.0
# via wipac-telemetry
opentelemetry-proto==1.22.0
opentelemetry-proto==1.23.0
# via
# opentelemetry-exporter-otlp-proto-common
# opentelemetry-exporter-otlp-proto-http
opentelemetry-sdk==1.22.0
opentelemetry-sdk==1.23.0
# via
# opentelemetry-exporter-jaeger-proto-grpc
# opentelemetry-exporter-jaeger-thrift
# opentelemetry-exporter-otlp-proto-http
# wipac-telemetry
opentelemetry-semantic-conventions==0.43b0
opentelemetry-semantic-conventions==0.44b0
# via opentelemetry-sdk
prometheus-client==0.19.0
prometheus-client==0.20.0
# via lta (setup.py)
protobuf==4.25.2
protobuf==4.25.3
# via
# googleapis-common-protos
# opentelemetry-proto
# wipac-telemetry
pycparser==2.21
# via cffi
pyjwt[crypto]==2.8.0
# via
# pyjwt
# wipac-rest-tools
pymongo==4.6.1
# via wipac-rest-tools
pymongo==4.6.2
# via
# lta (setup.py)
# motor
Expand Down Expand Up @@ -144,12 +136,12 @@ typing-extensions==4.9.0
# qrcode
# wipac-dev-tools
# wipac-telemetry
urllib3==2.1.0
urllib3==2.2.1
# via
# elasticsearch
# requests
# wipac-rest-tools
wipac-dev-tools==1.8.2
wipac-dev-tools==1.9.1
# via
# lta (setup.py)
# wipac-rest-tools
Expand Down
Loading

0 comments on commit 42b64d4

Please sign in to comment.