33from ngcsimlib .logger import warn
44from functools import wraps
55from ngcsimlib .utils import add_component_transition , add_transition_meta
6- from ngcsimlib .utils import get_current_context , get_context , infer_context
6+ from ngcsimlib .utils import get_current_context , infer_context , Set_Compartment_Batch
77
88class Process (object ):
99 def __init__ (self , name ):
1010 self ._method = None
1111 self ._calls = []
1212 self .name = name
13+ self ._needed_contexts = set ([])
1314
1415 cc = get_current_context ()
15- print (get_current_context ())
1616 if cc is not None :
1717 cc .register_process (self )
1818
1919 @staticmethod
2020 def make_process (process_spec ):
21- print (process_spec )
2221 newProcess = Process (process_spec ['name' ])
2322
2423 for x in process_spec ['calls' ]:
@@ -37,19 +36,32 @@ def __rshift__(self, other):
3736
3837 def transition (self , transition_call ):
3938 self ._calls .append ({"path" : transition_call .__self__ .path , "key" : transition_call .resolver_key })
39+ self ._needed_contexts .add (infer_context (transition_call .__self__ .path ))
4040 new_step = compile_component (transition_call )
4141 self ._method = compose (self ._method , new_step )
4242 return self
4343
44- def execute (self , current_state , ** kwargs ):
44+ def execute (self , update_state = False , ** kwargs ):
4545 if self ._method is None :
4646 warn ("Attempting to execute a process with no transition steps" )
4747 return
48- return self .pure (current_state , ** kwargs )
48+ state = self .pure (self .get_required_state (), ** kwargs )
49+ if update_state :
50+ self .updated_modified_state (state )
51+ return state
4952
5053 def as_obj (self ):
5154 return {"name" : self .name , "calls" : self ._calls }
5255
56+ def get_required_state (self ):
57+ compound_state = {}
58+ for context in self ._needed_contexts :
59+ compound_state .update (context .get_current_state ())
60+ return compound_state
61+
62+ @classmethod
63+ def updated_modified_state (cls , modified_state ):
64+ Set_Compartment_Batch (modified_state )
5365
5466
5567def transition (output_compartments ):
0 commit comments