Skip to content

Commit

Permalink
split clients to PROD and DEV
Browse files Browse the repository at this point in the history
  • Loading branch information
Foroxon committed Apr 1, 2024
1 parent 5d56c12 commit 22ff00c
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
3 changes: 2 additions & 1 deletion deploy/redeploy_websocket_server.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ MEMCACHED_HOST=""
WEBSOCKET_PORT=38440
DEBUG_LEVEL="INFO"
PING_INTERVAL=60
ENVIRONMENT="PROD"

# Check for arguments
while [[ $# -gt 0 ]]; do
Expand Down Expand Up @@ -68,7 +69,7 @@ docker rm map_websocket_server || true

# Deploying the new container
echo "Deploying new container..."
docker run --name map_websocket_server --restart unless-stopped -d -p "$WEBSOCKET_PORT":"$WEBSOCKET_PORT" --env WEBSOCKET_PORT="$WEBSOCKET_PORT" --env API_SECRET="$API_SECRET" --env MEASUREMENT_ID="$MEASUREMENT_ID" --env DEBUG_LEVEL="$DEBUG_LEVEL" --env PING_INTERVAL="$PING_INTERVAL" --env MEMCACHED_HOST="$MEMCACHED_HOST" map_websocket_server
docker run --name map_websocket_server --restart unless-stopped -d -p "$WEBSOCKET_PORT":"$WEBSOCKET_PORT" --env WEBSOCKET_PORT="$WEBSOCKET_PORT" --env API_SECRET="$API_SECRET" --env MEASUREMENT_ID="$MEASUREMENT_ID" --env DEBUG_LEVEL="$DEBUG_LEVEL" --env PING_INTERVAL="$PING_INTERVAL" --env MEMCACHED_HOST="$MEMCACHED_HOST" ---env ENVIRONMENT="$ENVIRONMENT" map_websocket_server

echo "Container deployed successfully!"

3 changes: 2 additions & 1 deletion deploy/redeploy_websocket_server_dev.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ MEMCACHED_HOST=""
WEBSOCKET_PORT=38447
DEBUG_LEVEL="INFO"
PING_INTERVAL=60
ENVIRONMENT="DEV"

# Check for arguments
while [[ $# -gt 0 ]]; do
Expand Down Expand Up @@ -68,7 +69,7 @@ docker rm map_websocket_server_dev || true

# Deploying the new container
echo "Deploying new container..."
docker run --name map_websocket_server_dev --restart unless-stopped -d -p "$WEBSOCKET_PORT":"$WEBSOCKET_PORT" --env WEBSOCKET_PORT="$WEBSOCKET_PORT" --env API_SECRET="$API_SECRET" --env MEASUREMENT_ID="$MEASUREMENT_ID" --env DEBUG_LEVEL="$DEBUG_LEVEL" --env PING_INTERVAL="$PING_INTERVAL" --env MEMCACHED_HOST="$MEMCACHED_HOST" map_websocket_server_dev
docker run --name map_websocket_server_dev --restart unless-stopped -d -p "$WEBSOCKET_PORT":"$WEBSOCKET_PORT" --env WEBSOCKET_PORT="$WEBSOCKET_PORT" --env API_SECRET="$API_SECRET" --env MEASUREMENT_ID="$MEASUREMENT_ID" --env DEBUG_LEVEL="$DEBUG_LEVEL" --env PING_INTERVAL="$PING_INTERVAL" --env MEMCACHED_HOST="$MEMCACHED_HOST" ---env ENVIRONMENT="$ENVIRONMENT" map_websocket_server_dev

echo "Container deployed successfully!"

5 changes: 4 additions & 1 deletion deploy/web_server/web_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,11 +416,14 @@ async def stats(request):

websocket_clients = await mc.get(b'websocket_clients')
websocket_clients_data = json.loads(websocket_clients.decode('utf-8')) if websocket_clients else {}
websocket_clients_dev = await mc.get(b'websocket_clients_dev')
websocket_clients_dev_data = json.loads(websocket_clients_dev.decode('utf-8')) if websocket_clients_dev else {}

tcp_clients = await dataparcer(tcp_clients_data, 'tcp')
websocket_clients = await dataparcer(websocket_clients_data, 'websockets')
websocket_clients_dev = await dataparcer(websocket_clients_dev_data, 'websockets_dev')

map_clients_data = tcp_clients + websocket_clients
map_clients_data = tcp_clients + websocket_clients + websocket_clients_dev

return JSONResponse ({

Expand Down
4 changes: 3 additions & 1 deletion deploy/websocket_server/websocket_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
random_mode = os.environ.get('RANDOM_MODE') or False
api_secret = os.environ.get('API_SECRET') or ''
measurement_id = os.environ.get('MEASUREMENT_ID') or ''
environment = os.environ.get('ENVIRONMENT') or 'PROD'

logging.basicConfig(level=debug_level,
format='%(asctime)s %(levelname)s : %(message)s')
Expand Down Expand Up @@ -341,7 +342,8 @@ async def print_clients(shared_data, mc):
logger.info(f"Clients:")
for client, data in shared_data.clients.items():
logger.info(client)
await mc.set(b"websocket_clients", json.dumps(shared_data.clients).encode('utf-8'))
websoket_key = b"websocket_clients" if environment == 'PROD' else b"websocket_clients_dev"
await mc.set(websoket_key, json.dumps(shared_data.clients).encode('utf-8'))
except Exception as e:
logger.error(f"Error in update_shared_data: {e}")

Expand Down

0 comments on commit 22ff00c

Please sign in to comment.