Skip to content

Commit a0d5c1c

Browse files
author
Alan Christie
committed
style: Better deployment and reader logging
1 parent ef99390 commit a0d5c1c

File tree

5 files changed

+21
-7
lines changed

5 files changed

+21
-7
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ Once deployed the application's internal API will be behind the service
9292
`ess-internal-api` on port `8001`. The Account Server will be able to
9393
manage event streams via the URL `http://ess-internal-api:8001/event-stream/`.
9494

95+
To update the running image (to deploy a new tagged version) just re-run the
96+
playbook with the a suitable value for `ess_image_tag`.
97+
9598
To remove the application run the playbook again, but set the `ess_state` variable
9699
to `absent`: -
97100

ansible/parameters-template.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
# and add any additional variables and values to suit your installation in this file.
88

99
ess_namespace: SetMe
10+
ess_image_tag: SetMe
1011
ess_service_account: SetMe
1112
ess_ws_hostname: SetMe
1213
ess_ampq_url: SetMe

ansible/roles/app/defaults/main.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ ess_ws_hostname: SetMe
1717
# This must include a username and password and typically an exchange.
1818
# For example 'amqp://username:password@rabbitmq:5672/es'
1919
ess_ampq_url: SetMe
20+
# What image tag do you want to deploy?
21+
ess_image_tag: SetMe
2022

2123
# Required with defaults ---------------------------------------------------------------
2224

@@ -28,7 +30,6 @@ ess_ingress_state: present
2830

2931
# Our image details
3032
ess_image_owner: informaticsmatters
31-
ess_image_tag: 1.0.0-beta.3
3233

3334
# Pull Policy? Always or IfNotPresent
3435
ess_pull_policy_always: IfNotPresent

ansible/roles/app/tasks/deploy.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
that:
66
- ess_namespace | length > 0
77
- ess_namespace != 'SetMe'
8+
- ess_image_tag | length > 0
9+
- ess_image_tag != 'SetMe'
810
- ess_service_account | length > 0
911
- ess_service_account != 'SetMe'
1012
- ess_ws_hostname | length > 0

app/app.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ async def event_stream(websocket: WebSocket, uuid: str):
7575
using a POST to /event-stream/."""
7676

7777
# Get the DB record for this UUID...
78+
_LOGGER.debug("Connect attempt (uuid=%s)...", uuid)
7879
db = sqlite3.connect(_DATABASE_PATH)
7980
cursor = db.cursor()
8081
res = cursor.execute(f"SELECT * FROM es WHERE uuid='{uuid}'")
@@ -91,19 +92,25 @@ async def event_stream(websocket: WebSocket, uuid: str):
9192
es_id = es[0]
9293
routing_key: str = es[2]
9394

94-
await websocket.accept()
95-
_LOGGER.info(
96-
"Accepted connection for %s (uuid=%s routing_key=%s)", es_id, uuid, routing_key
95+
_LOGGER.debug(
96+
"Waiting for accept on stream %s (uuid=%s routing_key=%s)...",
97+
es_id,
98+
uuid,
99+
routing_key,
97100
)
101+
await websocket.accept()
102+
_LOGGER.debug("Accepted connection for %s", es_id)
98103

99-
_LOGGER.info("Creating reader for %s...", es_id)
104+
_LOGGER.debug("Creating reader for %s...", es_id)
100105
message_reader = _get_from_queue(routing_key)
101106

102-
_LOGGER.info("Reading from %s...", es_id)
107+
_LOGGER.debug("Reading %s...", es_id)
103108
while True:
104109
reader = anext(message_reader)
105110
message_body = await reader
106-
_LOGGER.info("Got %s for %s (routing_key=%s)", message_body, es_id, routing_key)
111+
_LOGGER.debug(
112+
"Got %s for %s (routing_key=%s)", message_body, es_id, routing_key
113+
)
107114
await websocket.send_text(str(message_body))
108115

109116

0 commit comments

Comments
 (0)