Spaces:
Sleeping
Sleeping
File size: 2,259 Bytes
a03bb33 e989cbd 51889d0 a03bb33 167589c 2e00b37 167589c a03bb33 167589c f777ef6 da09feb 167589c f777ef6 8639ffe 5d8b2f6 167589c f777ef6 167589c a03bb33 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | import time
import threading
from core.state import job_queue, state
from core.database import db_manager
from core.tasks import run_audio_processing
def queue_worker():
while True:
try:
job = job_queue.get()
if job is None:
break
if isinstance(job, dict):
task_type = job.get("type")
task_id = job.get("task_id")
else:
# Legacy tuple fallback
task_type = "audio"
task_id = job[0]
state.active_task_id = task_id
# Check if the task was cancelled while sitting in the queue
if task_id in state.cancelled_tasks:
state.active_task_id = None
job_queue.task_done()
continue
db_manager.upsert_task(task_id, {
"status": "processing",
"start_time": time.time()
})
if task_type == "audio":
if isinstance(job, tuple):
# Fallback for very old legacy tuple format
_, file_path, isolate_vocals, enhance_speech, lyric_sync, user_email = job[:6]
else:
args = job.get("args")
# Should be exactly 5 arguments now
if len(args) == 5:
file_path, isolate_vocals, enhance_speech, lyric_sync, user_email = args
else:
raise ValueError(f"Unexpected number of arguments in job: {len(args)}")
run_audio_processing(task_id, file_path, isolate_vocals, enhance_speech, lyric_sync, user_email)
state.active_task_id = None
job_queue.task_done()
except Exception as e:
print(f"CRITICAL ERROR IN WORKER THREAD: {e}")
try:
state.active_task_id = None
job_queue.task_done()
except:
pass
def start_worker():
worker_thread = threading.Thread(target=queue_worker, daemon=True)
worker_thread.start()
return worker_thread
|