54 lines
1.3 KiB
Python
54 lines
1.3 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""
|
|
Shared message protocol definitions for Server <-> Worker communication.
|
|
"""
|
|
from enum import Enum
|
|
|
|
|
|
class MsgType(str, Enum):
|
|
"""WebSocket message types."""
|
|
|
|
# Worker -> Server
|
|
REGISTER = "register"
|
|
HEARTBEAT = "heartbeat"
|
|
BROWSER_LIST_UPDATE = "browser_list_update"
|
|
TASK_PROGRESS = "task_progress"
|
|
TASK_RESULT = "task_result"
|
|
TASK_STATUS_REPORT = "task_status_report"
|
|
|
|
# Server -> Worker
|
|
REGISTER_ACK = "register_ack"
|
|
HEARTBEAT_ACK = "heartbeat_ack"
|
|
TASK_ASSIGN = "task_assign"
|
|
TASK_CANCEL = "task_cancel"
|
|
TASK_STATUS_QUERY = "task_status_query"
|
|
|
|
# Bidirectional
|
|
ERROR = "error"
|
|
|
|
|
|
class TaskStatus(str, Enum):
|
|
"""Task lifecycle states."""
|
|
|
|
PENDING = "pending"
|
|
DISPATCHED = "dispatched"
|
|
RUNNING = "running"
|
|
SUCCESS = "success"
|
|
FAILED = "failed"
|
|
CANCELLED = "cancelled"
|
|
|
|
|
|
class TaskType(str, Enum):
|
|
"""Supported task types."""
|
|
|
|
BOSS_RECRUIT = "boss_recruit" # New greeting flow (from 1.py main)
|
|
BOSS_REPLY = "boss_reply" # Old recruit flow, now reply flow
|
|
CHECK_LOGIN = "check_login"
|
|
SYNC_FILTERS = "sync_filters" # Fetch recruit filter options from site
|
|
|
|
|
|
def make_msg(msg_type: MsgType, **payload) -> dict:
|
|
"""Build a standard WebSocket JSON message."""
|
|
return {"type": msg_type.value, **payload}
|
|
|