Update to websockets
This commit is contained in:
@@ -16,4 +16,5 @@ pandas
|
|||||||
openpyxl
|
openpyxl
|
||||||
xlrd
|
xlrd
|
||||||
qrcode[pil]
|
qrcode[pil]
|
||||||
|
websockets
|
||||||
# mypy
|
# mypy
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
from fastapi import APIRouter, FastAPI, WebSocket, WebSocketDisconnect
|
from fastapi import APIRouter, FastAPI, Response, WebSocket, WebSocketDisconnect
|
||||||
from fastapi.responses import HTMLResponse
|
from fastapi.responses import HTMLResponse
|
||||||
from typing import List
|
from pydantic import BaseModel, EmailStr, Field
|
||||||
import aioredis, asyncio, json
|
from typing import Dict, List, Optional, Set, Union
|
||||||
|
import aioredis, asyncio, datetime, hashlib, json, os, pathlib, shutil, time
|
||||||
|
|
||||||
from app.lib_general import *
|
from app.lib_general import log, logging, common_route_params, Common_Route_Params, common_route_params_min, Common_Route_Params_Min
|
||||||
from ..log import *
|
|
||||||
from app.config import settings
|
from app.config import settings
|
||||||
from app.db_sql import *
|
from app.db_sql import sql_insert, sql_update, sql_insert_or_update, sql_select, sql_delete, redis_lookup_id_random
|
||||||
|
|
||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
|
|
||||||
@@ -29,8 +29,9 @@ html = """
|
|||||||
<script>
|
<script>
|
||||||
var client_id = Date.now()
|
var client_id = Date.now()
|
||||||
document.querySelector("#ws-id").textContent = client_id;
|
document.querySelector("#ws-id").textContent = client_id;
|
||||||
//var ws = new WebSocket(`ws://localhost:5005/ws/${client_id}`);
|
// var ws = new WebSocket(`ws://localhost:5005/ws/${client_id}`);
|
||||||
var ws = new WebSocket("ws://localhost:8000/ws");
|
var ws = new WebSocket(`ws://localhost:5005/ws`);
|
||||||
|
//var ws = new WebSocket("ws://localhost:8000/ws");
|
||||||
//var ws = new WebSocket("ws://fastapi.localhost/ws");
|
//var ws = new WebSocket("ws://fastapi.localhost/ws");
|
||||||
ws.onmessage = function(event) {
|
ws.onmessage = function(event) {
|
||||||
var messages = document.getElementById('messages')
|
var messages = document.getElementById('messages')
|
||||||
@@ -66,7 +67,9 @@ async def get(response: Response = Response):
|
|||||||
async def websocket_endpoint(websocket: WebSocket, response: Response = Response):
|
async def websocket_endpoint(websocket: WebSocket, response: Response = Response):
|
||||||
log.setLevel(logging.DEBUG)
|
log.setLevel(logging.DEBUG)
|
||||||
log.debug(locals())
|
log.debug(locals())
|
||||||
|
|
||||||
log.info('Root of ws. Waiting to accept a websocket and then the redis_connector')
|
log.info('Root of ws. Waiting to accept a websocket and then the redis_connector')
|
||||||
|
|
||||||
await websocket.accept()
|
await websocket.accept()
|
||||||
await redis_connector(websocket)
|
await redis_connector(websocket)
|
||||||
|
|
||||||
@@ -105,7 +108,7 @@ async def redis_connector(
|
|||||||
# TODO this needs handling better
|
# TODO this needs handling better
|
||||||
log.error(exc)
|
log.error(exc)
|
||||||
|
|
||||||
redis = await aioredis.create_redis_pool(redis_uri)
|
redis = await aioredis.create_pool(redis_uri)
|
||||||
|
|
||||||
consumer_task = consumer_handler(websocket, redis)
|
consumer_task = consumer_handler(websocket, redis)
|
||||||
producer_task = producer_handler(redis, websocket)
|
producer_task = producer_handler(redis, websocket)
|
||||||
|
|||||||
Reference in New Issue
Block a user