Delete worker.py
Browse files
worker.py
DELETED
|
@@ -1,32 +0,0 @@
|
|
| 1 |
-
from threading import Thread
|
| 2 |
-
from queue import Queue
|
| 3 |
-
from generate import generate_music
|
| 4 |
-
from cleanup import cleanup
|
| 5 |
-
|
| 6 |
-
job_queue = Queue()
|
| 7 |
-
jobs = {}
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
def worker():
|
| 11 |
-
|
| 12 |
-
while True:
|
| 13 |
-
job_id, prompt, duration = job_queue.get()
|
| 14 |
-
|
| 15 |
-
try:
|
| 16 |
-
jobs[job_id]["status"] = "processing"
|
| 17 |
-
|
| 18 |
-
file_path = generate_music(prompt, duration)
|
| 19 |
-
|
| 20 |
-
jobs[job_id]["status"] = "done"
|
| 21 |
-
jobs[job_id]["file"] = file_path
|
| 22 |
-
|
| 23 |
-
cleanup()
|
| 24 |
-
|
| 25 |
-
except Exception as e:
|
| 26 |
-
jobs[job_id]["status"] = "error"
|
| 27 |
-
jobs[job_id]["error"] = str(e)
|
| 28 |
-
|
| 29 |
-
job_queue.task_done()
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
Thread(target=worker, daemon=True).start()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|