@@ -63,18 +63,20 @@ def __init__(self, **kwargs):
6363 self ._on_fail_func = None
6464 self ._on_exit_func = None
6565
66- # Config wiring
67- self .source_config_file = self .config .source_config_file
68-
6966 # Backwards compatability
67+ self .source_config_file = self .config .source_config_file
7068 self .load_proc_list_file = self .load_from_file
7169 self .load_last_failed = self .load_state
7270
7371 if kwargs .get ('parse_args' , False ) == True :
7472 self .parse_args ()
7573
74+ def reset_env (self ):
75+ os .environ .clear ()
76+ os .environ .update (self ._environ )
77+
7678 def load_from_file (self , proc_file , restart = False ):
77- if not os .path .isfile (proc_file ):
79+ if not proc_file or not os .path .isfile (proc_file ):
7880 return False
7981
8082 self .register = self .serde_obj .deserialize (proc_file , restart )
@@ -123,6 +125,9 @@ def plugin_notification(self, obj):
123125 if not isinstance (obj , notification .Notification ): raise Exception ('Notification plugin must implement the Notification interface' )
124126 self .notification = obj
125127
128+ # App lifecycle hooks
129+ def on_fresh_start (self , func ):
130+ self ._on_fresh_start_func = func
126131 def on_start (self , func ):
127132 self ._on_start_func = func
128133 def on_restart (self , func ):
@@ -134,9 +139,7 @@ def on_fail(self, func):
134139 def on_exit (self , func ):
135140 self ._on_exit_func = func
136141
137- def execute (self ):
138- return self .run ()
139- def run (self ):
142+ def prepare (self ):
140143 # Source config
141144 self .source_config_file (self ._init_params ['config_file' ])
142145
@@ -159,14 +162,22 @@ def run(self):
159162 self .exec_from (self ._init_params ['exec_from_id' ])
160163 if self ._init_params ['exec_to_id' ] is not None :
161164 self .exec_to (self ._init_params ['exec_to_id' ])
165+
166+ def execute (self ):
167+ return self .run ()
168+ def run (self ):
169+ self .prepare ()
162170
163171 # App lifecycle - START
164172 if self ._on_start_func :
165173 self ._on_start_func ()
166174
167175 # App lifecycle - RESTART
168- if self ._init_params ['restart' ] and self ._on_restart_func :
169- self ._on_restart_func ()
176+ if self ._init_params ['restart' ]:
177+ if self ._on_restart_func : self ._on_restart_func ()
178+ # App lifecycle - FRESH START
179+ else :
180+ if self ._on_fresh_start_func : self ._on_fresh_start_func ()
170181
171182 self .config ['app_start_time' ] = datetime .now ().strftime ('%Y-%m-%d %H:%M:%S' )
172183
0 commit comments