@@ -6,7 +6,7 @@ use crate::{
66use core:: pin:: Pin ;
77use dandelion_commons:: {
88 records:: { RecordPoint , Recorder } ,
9- DandelionResult , FunctionId ,
9+ DandelionError , DandelionResult , DispatcherError , FunctionId ,
1010} ;
1111use futures:: {
1212 future:: { join_all, ready, Either } ,
@@ -102,14 +102,13 @@ impl Dispatcher {
102102
103103 pub async fn queue_function_by_name (
104104 & self ,
105- function_name : String ,
105+ function_id : Arc < String > ,
106106 inputs : Vec < DispatcherInput > ,
107107 caching : bool ,
108- start_time : std :: time :: Instant ,
108+ mut recorder : Recorder ,
109109 ) -> DandelionResult < ( Vec < Option < CompositionSet > > , Recorder ) > {
110- debug ! ( "Queuing function {}" , function_name) ;
111- let function_id = Arc :: new ( function_name) ;
112- let recorder = Recorder :: new ( function_id. clone ( ) , start_time) ;
110+ debug ! ( "Queuing function {}" , function_id) ;
111+ recorder. record ( RecordPoint :: EnterDispatcher ) ;
113112
114113 let mut input_vec = Vec :: with_capacity ( inputs. len ( ) ) ;
115114 input_vec. resize ( inputs. len ( ) , None ) ;
@@ -130,6 +129,53 @@ impl Dispatcher {
130129 return Ok ( ( results, recorder) ) ;
131130 }
132131
132+ pub async fn queue_unregistered_composition (
133+ & self ,
134+ composition_desc : String ,
135+ inputs : Vec < DispatcherInput > ,
136+ caching : bool ,
137+ recorder : Recorder ,
138+ ) -> DandelionResult < ( Vec < Option < CompositionSet > > , Recorder ) > {
139+ debug ! ( "Parsing single use composition" ) ;
140+ let composition_meta_pairs = self
141+ . function_registry
142+ . parse_compositions ( & composition_desc. as_str ( ) ) ?;
143+ if composition_meta_pairs. len ( ) != 1 {
144+ debug ! (
145+ "Expected exactly one composition got {}" ,
146+ composition_meta_pairs. len( )
147+ ) ;
148+ return Err ( DandelionError :: Dispatcher (
149+ DispatcherError :: InvalidComposition ,
150+ ) ) ;
151+ }
152+
153+ debug ! (
154+ "Queuing single use composition {}" ,
155+ composition_meta_pairs[ 0 ] . 0
156+ ) ;
157+ let mut input_vec = Vec :: with_capacity ( inputs. len ( ) ) ;
158+ input_vec. resize ( inputs. len ( ) , None ) ;
159+ for ( index, input) in inputs. into_iter ( ) . enumerate ( ) {
160+ match input {
161+ DispatcherInput :: None => ( ) ,
162+ DispatcherInput :: Set ( set) => {
163+ input_vec[ index] = Some ( set) ;
164+ }
165+ }
166+ }
167+ let results = self
168+ . queue_composition (
169+ composition_meta_pairs[ 0 ] . 1 . clone ( ) ,
170+ input_vec,
171+ caching,
172+ recorder. get_sub_recorder ( ) ,
173+ )
174+ . await ?;
175+
176+ return Ok ( ( results, recorder) ) ;
177+ }
178+
133179 /// Queue a composition for execution.
134180 /// Returns a Vec of sets with the index corresponding to the set index in the composition definition
135181 ///
@@ -432,7 +478,7 @@ impl Dispatcher {
432478 ) -> Pin <
433479 Box < dyn Future < Output = DandelionResult < Vec < Option < CompositionSet > > > > + ' dispatcher + Send > ,
434480 > {
435- trace ! ( "queueing function with id: {}" , function_id) ;
481+ debug ! ( "Queueing function with id: {}" , function_id) ;
436482 Box :: pin ( async move {
437483 // find an engine capable of running the function
438484 // TODO: think about more distinctions, that allow pushing chains of functions which can be executed by single engine,
@@ -447,7 +493,6 @@ impl Dispatcher {
447493
448494 let metadata = func_info. metadata ;
449495 // run on engine
450- recorder. record ( RecordPoint :: GetEngineQueue ) ;
451496 trace ! (
452497 "Running function {} with input sets {:?} and output sets {:?} and alternatives: {:?}" ,
453498 function_id,
@@ -473,12 +518,12 @@ impl Dispatcher {
473518 recorder. record ( RecordPoint :: FutureReturn ) ;
474519
475520 #[ cfg( feature = "log_function_stdio" ) ]
476- for opt in result . content . iter ( ) {
521+ for opt in context . content . iter ( ) {
477522 if opt. as_ref ( ) . is_some_and ( |s| s. ident == "stdio" ) {
478523 for itm in opt. as_ref ( ) . unwrap ( ) . buffers . iter ( ) {
479524 if itm. ident == "stderr" && itm. data . size > 0 {
480525 let mut stderr_output: Vec < u8 > = vec ! [ 0 ; itm. data. size] ;
481- result . context . read ( itm. data . offset , & mut stderr_output) ?;
526+ context . context . read ( itm. data . offset , & mut stderr_output) ?;
482527 warn ! (
483528 "Function result contains stderr output:\n {}" ,
484529 std:: str :: from_utf8( stderr_output. as_slice( ) )
@@ -487,7 +532,7 @@ impl Dispatcher {
487532 }
488533 if itm. ident == "stdout" && itm. data . size > 0 {
489534 let mut stdout_output: Vec < u8 > = vec ! [ 0 ; itm. data. size] ;
490- result . context . read ( itm. data . offset , & mut stdout_output) ?;
535+ context . context . read ( itm. data . offset , & mut stdout_output) ?;
491536 debug ! (
492537 "Function output:\n {}" ,
493538 std:: str :: from_utf8( stdout_output. as_slice( ) )
0 commit comments