docker: add container websocket in docker-compose

This commit is contained in:
2025-04-27 14:14:32 -03:00
parent d5d136fc5d
commit e33f9e2974
7 changed files with 33 additions and 17 deletions

View File

@@ -0,0 +1,14 @@
FROM python:3.12-slim
WORKDIR /app
RUN apt-get update && apt-get install -y git && apt-get clean
RUN git clone https://github.com/welton89/websocket-RRBEC.git /app
RUN pip install --upgrade pip && pip install websockets
EXPOSE 8765
CMD ["python", "websocket_server.py"]

View File

@@ -55,6 +55,16 @@ services:
networks: networks:
- app_network - app_network
websocket_server:
build:
context: ./WebSocketServer
dockerfile: Dockerfile
ports:
- "8765:8765"
restart: on-failure
networks:
- app_network
volumes: volumes:
static_volume: static_volume:
db_data: db_data:

View File

@@ -15,17 +15,15 @@ import websockets
async def enviar_mensagem(msg): async def enviar_mensagem(msg):
try: try:
uri = "ws://192.168.1.150:8765" uri = "ws://websocket_server:8765"
async with websockets.connect(uri) as websocket: async with websockets.connect(uri) as websocket:
await websocket.send(msg) await websocket.send(msg)
print(f"> Enviado: {msg}") # print(f"> Enviado: {msg}")
resposta = await websocket.recv() # resposta = await websocket.recv()
print(f"< Recebido: {resposta}") # print(f"< Recebido: {resposta}")
except Exception as e: except Exception as e:
print(f"Erro ao enviar mensagem: {e}") print(f"Erro ao enviar mensagem via websocket: {e}")
def somar(consumo:ProductComanda, comanda:Comanda): def somar(consumo:ProductComanda, comanda:Comanda):
@@ -87,7 +85,7 @@ def addProduct(request, product_id, comanda_id):
'speak': f'Novo pedido! {product.name}, para {comanda.name}.' 'speak': f'Novo pedido! {product.name}, para {comanda.name}.'
}) })
# asyncio.run(enviar_mensagem(msg)) asyncio.run(enviar_mensagem(msg))
consumo = ProductComanda.objects.filter(comanda=comanda_id) consumo = ProductComanda.objects.filter(comanda=comanda_id)
valores = somar(consumo,comanda) valores = somar(consumo,comanda)

View File

@@ -98,7 +98,6 @@ def addContaCliente(request):
clientId = int(request.POST.get('select-client')) clientId = int(request.POST.get('select-client'))
comanda = Comanda.objects.get(id=comandaId) comanda = Comanda.objects.get(id=comandaId)
client = Client.objects.get(id=clientId) client = Client.objects.get(id=clientId)
# client.debt = Decimal(0)
comanda.client = client comanda.client = client
comanda.dt_close = timezone.now() comanda.dt_close = timezone.now()
comanda.status = 'FIADO' comanda.status = 'FIADO'

View File

@@ -17,13 +17,13 @@ RRB&C - DashBoard
<input id="data-start" name="data-start" oninput="mediaCuisine()" type="date"> <input id="data-start" name="data-start" oninput="mediaCuisine()" type="date">
<input id="data-end" name="data-end" oninput="mediaCuisine()" type="date"> <input id="data-end" name="data-end" oninput="mediaCuisine()" type="date">
</div> </div>
<h4 id="30-days">Últimos 30 diAs</h4> <h4 id="30-days">Últimos 30 dias</h4>
</div> </div>
<div class="grid-container"> <div class="grid-container">
<div class="card-resumo"> <div class="card-resumo">
<div> <div>
<p> Faturament0 </p> <p> Faturamento </p>
<h2 id="total-pagamentos">Carregando... </h2> <h2 id="total-pagamentos">Carregando... </h2>
</div> </div>
<img src="{% static 'midia/icons/money-bag.svg' %}" > <img src="{% static 'midia/icons/money-bag.svg' %}" >

View File

@@ -19,11 +19,6 @@ document.addEventListener('DOMContentLoaded', function() {
function verificarCookieNotificacao() { function verificarCookieNotificacao() {
var iconNotify = document.getElementById('icon-notify'); var iconNotify = document.getElementById('icon-notify');
if (document.cookie.indexOf('notificacao=') === -1) { if (document.cookie.indexOf('notificacao=') === -1) {
@@ -56,7 +51,7 @@ function cookieNotificacao() {
} }
} }
const websocket = new WebSocket('ws://192.168.1.150:8765'); const websocket = new WebSocket('ws://0.0.0.0:8765');
const nomeUsuario = document.getElementById('user-info').textContent; const nomeUsuario = document.getElementById('user-info').textContent;
websocket.addEventListener('open', (event) => { websocket.addEventListener('open', (event) => {