Spaces:
Running
Running
task done
Browse files
app.py
CHANGED
@@ -78,25 +78,33 @@ q = queue.Queue()
|
|
78 |
def process_queue(q):
|
79 |
while True:
|
80 |
try:
|
81 |
-
key, censor, offset, text, format, speed, crossfade, id, receiver, webhook = q.get(timeout=5)
|
82 |
-
|
|
|
|
|
83 |
convertedAudioPath = convert(audio, format)
|
84 |
duration = get_audio_duration(convertedAudioPath)
|
85 |
audioUrl = upload_to_s3(convertedAudioPath, f"{id}", format)
|
|
|
86 |
os.remove(audio)
|
87 |
os.remove(convertedAudioPath)
|
88 |
-
|
89 |
payload = {
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
requests.post(webhook, json=payload)
|
|
|
|
|
|
|
|
|
97 |
except Exception as e:
|
98 |
-
print(e)
|
99 |
-
|
|
|
100 |
q.task_done()
|
101 |
|
102 |
worker_thread = threading.Thread(target=process_queue, args=(q,))
|
|
|
78 |
def process_queue(q):
|
79 |
while True:
|
80 |
try:
|
81 |
+
key, censor, offset, text, format, speed, crossfade, id, receiver, webhook = q.get(timeout=5)
|
82 |
+
|
83 |
+
# Processamento do item
|
84 |
+
audio = generate_audio(key, text, censor, offset, speed=speed, crossfade=crossfade)
|
85 |
convertedAudioPath = convert(audio, format)
|
86 |
duration = get_audio_duration(convertedAudioPath)
|
87 |
audioUrl = upload_to_s3(convertedAudioPath, f"{id}", format)
|
88 |
+
|
89 |
os.remove(audio)
|
90 |
os.remove(convertedAudioPath)
|
91 |
+
|
92 |
payload = {
|
93 |
+
"id": id,
|
94 |
+
"duration": duration,
|
95 |
+
"receiver": receiver,
|
96 |
+
"url": audioUrl
|
97 |
+
}
|
98 |
+
|
99 |
requests.post(webhook, json=payload)
|
100 |
+
|
101 |
+
except queue.Empty:
|
102 |
+
print("Queue timeout: no items to process.")
|
103 |
+
break
|
104 |
except Exception as e:
|
105 |
+
print(f"Error processing item: {e}")
|
106 |
+
else:
|
107 |
+
# Confirma que a tarefa foi concluída com sucesso
|
108 |
q.task_done()
|
109 |
|
110 |
worker_thread = threading.Thread(target=process_queue, args=(q,))
|