@@ -249,42 +249,84 @@ export default function Tasks() {
249249  const  handleQueue  =  async  ( task : any )  =>  { 
250250    if  ( ! experimentInfo ?. id )  return ; 
251251
252+     addNotification ( { 
253+       type : 'success' , 
254+       message : 'Creating job...' , 
255+     } ) ; 
256+ 
252257    try  { 
253258      const  cfg  = 
254259        typeof  task . config  ===  'string' 
255260          ? JSON . parse ( task . config ) 
256261          : task . config  ||  { } ; 
257-       const  formData  =  new  FormData ( ) ; 
258-       formData . append ( 'experimentId' ,  experimentInfo . id ) ; 
259-       if  ( cfg . cluster_name )  formData . append ( 'cluster_name' ,  cfg . cluster_name ) ; 
260-       if  ( cfg . command )  formData . append ( 'command' ,  cfg . command ) ; 
261-       // Prefer the task name as job/task name 
262-       if  ( task . name )  formData . append ( 'task_name' ,  task . name ) ; 
263-       if  ( cfg . cpus )  formData . append ( 'cpus' ,  String ( cfg . cpus ) ) ; 
264-       if  ( cfg . memory )  formData . append ( 'memory' ,  String ( cfg . memory ) ) ; 
265-       if  ( cfg . disk_space )  formData . append ( 'disk_space' ,  String ( cfg . disk_space ) ) ; 
266-       if  ( cfg . accelerators ) 
267-         formData . append ( 'accelerators' ,  String ( cfg . accelerators ) ) ; 
268-       if  ( cfg . num_nodes )  formData . append ( 'num_nodes' ,  String ( cfg . num_nodes ) ) ; 
269-       if  ( cfg . setup )  formData . append ( 'setup' ,  String ( cfg . setup ) ) ; 
270-       if  ( cfg . uploaded_dir_path ) 
271-         formData . append ( 'uploaded_dir_path' ,  String ( cfg . uploaded_dir_path ) ) ; 
272- 
273-       const  resp  =  await  chatAPI . authenticatedFetch ( 
274-         chatAPI . Endpoints . Jobs . LaunchRemote ( experimentInfo . id ) , 
275-         {  method : 'POST' ,  body : formData  } , 
262+ 
263+       // Create the actual remote job 
264+       const  createJobFormData  =  new  FormData ( ) ; 
265+       createJobFormData . append ( 'experimentId' ,  experimentInfo . id ) ; 
266+       if  ( cfg . cluster_name )  createJobFormData . append ( 'cluster_name' ,  cfg . cluster_name ) ; 
267+       if  ( cfg . command )  createJobFormData . append ( 'command' ,  cfg . command ) ; 
268+       if  ( task . name )  createJobFormData . append ( 'task_name' ,  task . name ) ; 
269+       if  ( cfg . cpus )  createJobFormData . append ( 'cpus' ,  String ( cfg . cpus ) ) ; 
270+       if  ( cfg . memory )  createJobFormData . append ( 'memory' ,  String ( cfg . memory ) ) ; 
271+       if  ( cfg . disk_space )  createJobFormData . append ( 'disk_space' ,  String ( cfg . disk_space ) ) ; 
272+       if  ( cfg . accelerators )  createJobFormData . append ( 'accelerators' ,  String ( cfg . accelerators ) ) ; 
273+       if  ( cfg . num_nodes )  createJobFormData . append ( 'num_nodes' ,  String ( cfg . num_nodes ) ) ; 
274+       if  ( cfg . setup )  createJobFormData . append ( 'setup' ,  String ( cfg . setup ) ) ; 
275+       if  ( cfg . uploaded_dir_path )  createJobFormData . append ( 'uploaded_dir_path' ,  String ( cfg . uploaded_dir_path ) ) ; 
276+ 
277+       const  createJobResp  =  await  chatAPI . authenticatedFetch ( 
278+         chatAPI . Endpoints . Jobs . CreateRemoteJob ( experimentInfo . id ) , 
279+         {  method : 'POST' ,  body : createJobFormData  } , 
276280      ) ; 
277-       const  result  =  await  resp . json ( ) ; 
278-       if  ( result . status  ===  'success' )  { 
281+       const  createJobResult  =  await  createJobResp . json ( ) ; 
282+ 
283+       if  ( createJobResult . status  ===  'success' )  { 
284+         // Keep placeholder visible and refresh jobs list 
285+         // The placeholder will be replaced when the real job appears 
286+         await  jobsMutate ( ) ; 
287+ 
279288        addNotification ( { 
280289          type : 'success' , 
281-           message : 'Task queued for remote launch .' , 
290+           message : 'Job created. Launching remotely.. .' , 
282291        } ) ; 
283-         await  Promise . all ( [ jobsMutate ( ) ,  tasksMutate ( ) ] ) ; 
292+ 
293+         // Then launch the remote job 
294+         const  launchFormData  =  new  FormData ( ) ; 
295+         launchFormData . append ( 'experimentId' ,  experimentInfo . id ) ; 
296+         launchFormData . append ( 'job_id' ,  createJobResult . job_id ) ; 
297+         if  ( cfg . cluster_name )  launchFormData . append ( 'cluster_name' ,  cfg . cluster_name ) ; 
298+         if  ( cfg . command )  launchFormData . append ( 'command' ,  cfg . command ) ; 
299+         if  ( task . name )  launchFormData . append ( 'task_name' ,  task . name ) ; 
300+         if  ( cfg . cpus )  launchFormData . append ( 'cpus' ,  String ( cfg . cpus ) ) ; 
301+         if  ( cfg . memory )  launchFormData . append ( 'memory' ,  String ( cfg . memory ) ) ; 
302+         if  ( cfg . disk_space )  launchFormData . append ( 'disk_space' ,  String ( cfg . disk_space ) ) ; 
303+         if  ( cfg . accelerators )  launchFormData . append ( 'accelerators' ,  String ( cfg . accelerators ) ) ; 
304+         if  ( cfg . num_nodes )  launchFormData . append ( 'num_nodes' ,  String ( cfg . num_nodes ) ) ; 
305+         if  ( cfg . setup )  launchFormData . append ( 'setup' ,  String ( cfg . setup ) ) ; 
306+         if  ( cfg . uploaded_dir_path )  launchFormData . append ( 'uploaded_dir_path' ,  String ( cfg . uploaded_dir_path ) ) ; 
307+ 
308+         const  launchResp  =  await  chatAPI . authenticatedFetch ( 
309+           chatAPI . Endpoints . Jobs . LaunchRemote ( experimentInfo . id ) , 
310+           {  method : 'POST' ,  body : launchFormData  } , 
311+         ) ; 
312+         const  launchResult  =  await  launchResp . json ( ) ; 
313+ 
314+         if  ( launchResult . status  ===  'success' )  { 
315+           addNotification ( { 
316+             type : 'success' , 
317+             message : 'Task launched remotely.' , 
318+           } ) ; 
319+           await  Promise . all ( [ jobsMutate ( ) ,  tasksMutate ( ) ] ) ; 
320+         }  else  { 
321+           addNotification ( { 
322+             type : 'danger' , 
323+             message : `Remote launch failed: ${ launchResult . message }  , 
324+           } ) ; 
325+         } 
284326      }  else  { 
285327        addNotification ( { 
286328          type : 'danger' , 
287-           message : `Remote launch failed : ${ result . message }  , 
329+           message : `Failed to create job : ${ createJobResult . message }  , 
288330        } ) ; 
289331      } 
290332    }  catch  ( e )  { 
0 commit comments