updated skeleton with true data
This commit is contained in:
25
gateway/core/queue_client.py
Normal file
25
gateway/core/queue_client.py
Normal file
@ -0,0 +1,25 @@
|
||||
import redis, uuid, json, time, os
|
||||
|
||||
REDIS_HOST = os.environ.get("REDIS_HOST", "redis")
|
||||
r = redis.Redis(host=REDIS_HOST, port=6379, db=0)
|
||||
|
||||
QUEUE="tts_queue"
|
||||
RESULT="tts_result"
|
||||
|
||||
def push_job(data: dict) -> str:
|
||||
job_id = str(uuid.uuid4())
|
||||
data["job_id"] = job_id
|
||||
r.lpush(QUEUE, json.dumps(data))
|
||||
return job_id
|
||||
|
||||
def await_result(job_id: str, timeout=30):
|
||||
key = f"{RESULT}:{job_id}"
|
||||
start=time.time()
|
||||
while time.time()-start < timeout:
|
||||
data=r.get(key)
|
||||
if data:
|
||||
r.delete(key)
|
||||
obj=json.loads(data)
|
||||
return bytes.fromhex(obj["audio"]), obj["mime"]
|
||||
time.sleep(0.1)
|
||||
raise TimeoutError("Worker antwortet nicht")
|
||||
Reference in New Issue
Block a user