@@ -73,30 +73,39 @@ export function submitPlan(
7373 return blueApiCall ( "/tasks" , "POST" , {
7474 name : planName ,
7575 params : planParams ,
76- } )
77- . then ( ( res ) => {
78- if ( ! res . ok ) {
79- throw new Error (
80- `Unable to POST request,response error ${ res . statusText } `
81- ) ;
82- }
83- res . json ( ) ;
84- } )
85- . then ( ( res ) => res [ "task_id" ] ) ; // This probably needs to be done separately or something
86- // .catch((error) => console.log(error));
76+ } ) . then ( ( res ) => res . json ( ) . then ( ( res ) => res [ "task_id" ] ) ) ;
77+ }
78+
79+ export function submitTask (
80+ planName : string ,
81+ planParams : object
82+ ) : Promise < object | void > {
83+ return blueApiCall ( "/tasks" , "POST" , {
84+ name : planName ,
85+ params : planParams ,
86+ } ) . then ( ( res ) => {
87+ if ( ! res . ok ) {
88+ throw new Error (
89+ `Unable to POST request,response error ${ res . statusText } `
90+ ) ;
91+ }
92+ res . json ( ) ;
93+ } ) ;
8794}
8895
8996export function submitAndRunPlanImmediately (
9097 planName : string ,
9198 planParams : object
9299) : Promise < string > {
93- return submitPlan ( planName , planParams ) . then ( ( res ) =>
94- // TODO make sure submitPlan was succesful before then putting it to the worker
95- // See https://github.com/DiamondLightSource/mx-daq-ui/issues/17
96- blueApiCall ( "/worker/task" , "PUT" , { task_id : res } ) . then ( ( res ) =>
97- res . json ( ) . then ( ( res ) => res [ "task_id" ] )
100+ return submitPlan ( planName , planParams )
101+ . then ( ( res ) =>
102+ // TODO make sure submitPlan was succesful before then putting it to the worker
103+ // See https://github.com/DiamondLightSource/mx-daq-ui/issues/17
104+ blueApiCall ( "/worker/task" , "PUT" , { task_id : res } ) . then ( ( res ) =>
105+ res . json ( ) . then ( ( res ) => res [ "task_id" ] )
106+ )
98107 )
99- ) ;
108+ . catch ( ( error ) => console . log ( error ) ) ;
100109}
101110
102111export function abortCurrentPlan ( ) : Promise < BlueApiWorkerState > {
0 commit comments