Skip to content

Commit 64e1936

Browse files
author
Alan Christie
committed
fix: Fix messages and correct byte to string comparison
1 parent 96194a9 commit 64e1936

File tree

3 files changed

+34
-34
lines changed

3 files changed

+34
-34
lines changed

ansible/roles/app/templates/deployment.yaml.j2

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -40,32 +40,6 @@ spec:
4040
operator: Exists
4141

4242
containers:
43-
- name: memcached
44-
image: memcached:{{ ess_memcached_tag }}
45-
ports:
46-
- containerPort: 11211
47-
name: memcached
48-
env:
49-
- name: MEMCACHED_MAX_CONNECTIONS
50-
value: '{{ ess_memcached_max_connections }}'
51-
- name: MEMCACHED_MAX_ITEM_SIZE
52-
value: '36'
53-
- name: MEMCACHED_MEMORY_LIMIT
54-
value: '{{ ess_memcached_memory_limit }}'
55-
resources:
56-
requests:
57-
cpu: {{ ess_memcached_cpu_request }}
58-
memory: {{ ess_memcached_mem_request }}
59-
{% if ess_memcached_cpu_limit or ess_memcached_mem_limit %}
60-
limits:
61-
{% if ess_memcached_cpu_limit %}
62-
cpu: {{ ess_memcached_cpu_limit }}
63-
{% endif %}
64-
{% if ess_memcached_mem_limit %}
65-
memory: {{ ess_memcached_mem_limit }}
66-
{% endif %}
67-
{% endif %}
68-
6943
- name: ess
7044
image: {{ ess_image_owner }}/squonk2-fastapi-ws-event-stream:{{ ess_image_tag }}
7145
{% if ess_image_tag in ['latest', 'stable'] or ess_pull_policy_always %}
@@ -137,6 +111,32 @@ spec:
137111
{% if ess_api_mem_limit %}
138112
memory: {{ ess_api_mem_limit }}
139113
{% endif %}
114+
{% endif %}
115+
116+
- name: memcached
117+
image: memcached:{{ ess_memcached_tag }}
118+
ports:
119+
- containerPort: 11211
120+
name: memcached
121+
env:
122+
- name: MEMCACHED_MAX_CONNECTIONS
123+
value: '{{ ess_memcached_max_connections }}'
124+
- name: MEMCACHED_MAX_ITEM_SIZE
125+
value: '36'
126+
- name: MEMCACHED_MEMORY_LIMIT
127+
value: '{{ ess_memcached_memory_limit }}'
128+
resources:
129+
requests:
130+
cpu: {{ ess_memcached_cpu_request }}
131+
memory: {{ ess_memcached_mem_request }}
132+
{% if ess_memcached_cpu_limit or ess_memcached_mem_limit %}
133+
limits:
134+
{% if ess_memcached_cpu_limit %}
135+
cpu: {{ ess_memcached_cpu_limit }}
136+
{% endif %}
137+
{% if ess_memcached_mem_limit %}
138+
memory: {{ ess_memcached_mem_limit }}
139+
{% endif %}
140140
{% endif %}
141141

142142
volumes:

app/app.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -327,19 +327,19 @@ async def event_stream(
327327
# That's fine - the on_message_for_websocket() function will notice this
328328
# on the next message and should shut itself down.
329329
new_socket_uuid: str = python_uuid.uuid4()
330-
_LOGGER.warning(
331-
"Assigning unique WebSocket ID (%s) for this EventStream (routing_key=%s uuid=%s)",
330+
_LOGGER.info(
331+
"Assigning unique WebSocket ID (%s) for %s (routing_key=%s uuid=%s)",
332+
es_id,
332333
new_socket_uuid,
333334
es_routing_key,
334335
uuid,
335336
)
336-
existing_socket_uuid: str = _MEMCACHED_CLIENT.get(es_routing_key)
337+
existing_socket_uuid: str = _MEMCACHED_CLIENT.get(es_routing_key).decode("utf-8")
337338
if existing_socket_uuid and existing_socket_uuid != new_socket_uuid:
338339
_LOGGER.warning(
339-
"Replaced routing key %s WebSocket unique ID (%s) with ours (%s)",
340-
es_routing_key,
340+
"Replacing existing WebSocket unique ID (%s) with ours (id=%s)",
341341
existing_socket_uuid,
342-
new_socket_uuid,
342+
es_id,
343343
)
344344
_MEMCACHED_CLIENT.set(es_routing_key, new_socket_uuid)
345345

@@ -405,7 +405,7 @@ async def on_message_for_websocket(
405405
# (e.g. our UUID is not the value of the cached routing key im memcached).
406406
# This typically means we've been replaced by a new stream.
407407
# 2. We get a POISON message
408-
stream_socket_uuid: str = _MEMCACHED_CLIENT.get(es_routing_key)
408+
stream_socket_uuid: str = _MEMCACHED_CLIENT.get(es_routing_key).decode("utf-8")
409409
if stream_socket_uuid != es_websocket_uuid:
410410
_LOGGER.info(
411411
"There is a new owner of %s (%s), and it is not us (%s) (stopping)...",

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ services:
2222
container_name: memcached
2323
environment:
2424
MEMCACHED_MAX_ITEM_SIZE: 36
25-
MEMCACHED_MAX_CONNECTIONS: 8
25+
MEMCACHED_MAX_CONNECTIONS: 1
2626
MEMCACHED_MEMORY_LIMIT: 64
2727
ports:
2828
- '11211:11211'

0 commit comments

Comments
 (0)