@@ -54,9 +54,15 @@ def __init__(
5454
5555 def execute (self , job : QueueJob ) -> list [str ]:
5656 logger .info ("[QueueWorker] Executing GPU job %s (type=%s model=%s)" , job .id , job .type , job .model )
57- if job .type == "image" :
58- return self ._execute_image (job )
59- return self ._execute_video (job )
57+ # Pass the queue job ID to the generation handler so it can sync progress
58+ gen_handler = self ._video ._generation
59+ gen_handler .set_current_job_id (job .id )
60+ try :
61+ if job .type == "image" :
62+ return self ._execute_image (job )
63+ return self ._execute_video (job )
64+ finally :
65+ gen_handler .set_current_job_id (None )
6066
6167 def _execute_video (self , job : QueueJob ) -> list [str ]:
6268 p = job .params
@@ -104,35 +110,40 @@ def __init__(
104110 self ._image = image_generation
105111
106112 def execute (self , job : QueueJob ) -> list [str ]:
107- logger .info ("[QueueWorker] Executing API job %s (type=%s model=%s)" , job .id , job .type , job .model )
108- if job .type == "image" :
109- p = job .params
110- req = GenerateImageRequest (
111- prompt = _str (p , "prompt" ),
112- width = _int (p , "width" , 1920 ),
113- height = _int (p , "height" , 1080 ),
114- numImages = _int (p , "numImages" , 1 ),
115- numSteps = _int (p , "numSteps" , 4 ),
116- )
117- result = self ._image .generate (req )
118- return list (result .image_paths or [])
119- else :
120- p = job .params
121- req = GenerateVideoRequest (
122- prompt = _str (p , "prompt" ),
123- imagePath = _str (p , "imagePath" ) or None ,
124- lastFramePath = _str (p , "lastFramePath" ) or None ,
125- audioPath = _str (p , "audioPath" ) or None ,
126- resolution = _str (p , "resolution" , "540p" ),
127- duration = _str (p , "duration" , "5" ),
128- fps = _str (p , "fps" , "24" ),
129- audio = _str (p , "audio" , "false" ),
130- cameraMotion = _camera_motion (p ),
131- aspectRatio = _aspect_ratio (p ),
132- model = job .model ,
133- negativePrompt = _str (p , "negativePrompt" ),
134- )
135- result = self ._video .generate (req )
136- if result .video_path :
137- return [result .video_path ]
138- return []
113+ logger .info ("[QueueWorker] Executing API job %s (type=%s model=%s)" , job .id , job .id , job .type , job .model )
114+ gen_handler = self ._video ._generation
115+ gen_handler .set_current_job_id (job .id )
116+ try :
117+ if job .type == "image" :
118+ p = job .params
119+ req = GenerateImageRequest (
120+ prompt = _str (p , "prompt" ),
121+ width = _int (p , "width" , 1920 ),
122+ height = _int (p , "height" , 1080 ),
123+ numImages = _int (p , "numImages" , 1 ),
124+ numSteps = _int (p , "numSteps" , 4 ),
125+ )
126+ result = self ._image .generate (req )
127+ return list (result .image_paths or [])
128+ else :
129+ p = job .params
130+ req = GenerateVideoRequest (
131+ prompt = _str (p , "prompt" ),
132+ imagePath = _str (p , "imagePath" ) or None ,
133+ lastFramePath = _str (p , "lastFramePath" ) or None ,
134+ audioPath = _str (p , "audioPath" ) or None ,
135+ resolution = _str (p , "resolution" , "540p" ),
136+ duration = _str (p , "duration" , "5" ),
137+ fps = _str (p , "fps" , "24" ),
138+ audio = _str (p , "audio" , "false" ),
139+ cameraMotion = _camera_motion (p ),
140+ aspectRatio = _aspect_ratio (p ),
141+ model = job .model ,
142+ negativePrompt = _str (p , "negativePrompt" ),
143+ )
144+ result = self ._video .generate (req )
145+ if result .video_path :
146+ return [result .video_path ]
147+ return []
148+ finally :
149+ gen_handler .set_current_job_id (None )
0 commit comments