From 9002841933133977ab0bb1a8cbd655e7c067ac92 Mon Sep 17 00:00:00 2001 From: Jeremy Zhang Date: Wed, 30 Oct 2019 21:59:07 -0700 Subject: [PATCH] Use envvar TITAN_GATEWAY_ID to name each gateway workers --- webapp/titanembeds/blueprints/gateway/gateway.py | 4 +++- webapp/titanembeds/static/js/embed.js | 8 ++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/webapp/titanembeds/blueprints/gateway/gateway.py b/webapp/titanembeds/blueprints/gateway/gateway.py index e8f9e26..73826ae 100644 --- a/webapp/titanembeds/blueprints/gateway/gateway.py +++ b/webapp/titanembeds/blueprints/gateway/gateway.py @@ -5,6 +5,7 @@ import functools from flask import request, session import time import json +import os class Gateway(Namespace): def teardown_db_session(self): @@ -12,7 +13,8 @@ class Gateway(Namespace): db.session.remove() def on_connect(self): - emit('hello') + gateway_identifier = os.environ.get("TITAN_GATEWAY_ID", None) + emit('hello', {"gateway_identifier": gateway_identifier}) def on_identify(self, data): guild_id = data["guild_id"] diff --git a/webapp/titanembeds/static/js/embed.js b/webapp/titanembeds/static/js/embed.js index 9d804d5..e17093e 100644 --- a/webapp/titanembeds/static/js/embed.js +++ b/webapp/titanembeds/static/js/embed.js @@ -2122,6 +2122,14 @@ socket.emit('identify', {"guild_id": guild_id, "visitor_mode": visitor_mode}); process_message_users_cache(); }); + + socket.on('hello', function (msg) { + var gateway_identifier = msg.gateway_identifier; + if (!gateway_identifier) { + gateway_identifier = "null"; + } + console.log("%c[TitanEmbeds]%cConnected to gateway via%c" + gateway_identifier, 'color:aqua;background-color:black;border:1px solid black;padding: 3px;', 'color:white;background-color:black;border:1px solid black;padding: 3px;', 'color:white;background-color:black;border:1px solid black;font-family: Courier;padding: 3px;'); + }); socket.on("disconnect", function () {