BBSSJJ / CarbonCheckServer

0 stars 0 forks source link

작업요청: SSE 메세지 #15

Closed Gaebobman closed 1 year ago

Gaebobman commented 1 year ago

train_face에서 사용자 얼굴인식이 완료가 되면 ~/training_done 으로 HTTP POST 를 전송하도록 설정 해 놨습니다

    # Training done, Notify server
    url = f"https://{CARBONCHECK_SERVER_URL}/training_done"
    data = {'result': True}    # Header에 다음과 같은 정보가 들어갑니다.
    response = requests.post(url, data=data)
    # Check the response status code
    if response.status_code == 200:
        return 0
    else:
        return 1

서버에서는 이 POST 를 받게 되면 SSE 클라이언트에게 TRAINING DONE 이라는 데이터를 보내도록 할 수 있나요?

SSE Client 구현부는 여기 입니다.

def sse_client(url: str, headers: dict):
    # Create a SSE client object
    response = requests.get(url, stream=True, headers=headers)
    client = sseclient.SSEClient(response)
    # Receive events from the server
    for event in client.events():
        # Check the event data
        data = event.data
        if data.startswith("ADD USER"):
            # Extract the user_id from the data
            user_id = data.split()[2]
            terminate_process(DETECT_PY)
            # Create and start the train_faces.py process with user_id as argument
            processes[TRAIN_PY] = mp.Process(target=worker, args=(TRAIN_PY, user_id))
            processes[TRAIN_PY].start()
        elif data == "TRAINING DONE":
            # TRAIN_PY 종료
            terminate_process(TRAIN_PY)
            # Create and start the DETECT_PY process
            processes[DETECT_PY] = mp.Process(target=worker, args=(DETECT_PY,))
            processes[DETECT_PY].start()
Gaebobman commented 1 year ago

SSE server side Json Format

{"msg": "dummy \ add \ done", "id" : "string" \ Null "success": "true" \ Null }

BBSSJJ commented 1 year ago

작업 완료 3cde7be8b666269d601dcd877a21f35b8b2d8153