<s> import logging <EOL> import time <EOL> from util import full_stack <EOL> from django . utils . module_loading import import_by_path <EOL> from exceptions . error_codes import DBAAS_0001 <EOL> LOG = logging . getLogger ( __name__ ) <EOL> def start_workflow ( workflow_dict , task = None ) : <EOL> try : <EOL> if '<STR_LIT>' not in workflow_dict : <EOL> return False <EOL> workflow_dict [ '<STR_LIT>' ] = <NUM_LIT:0> <EOL> workflow_dict [ '<STR_LIT>' ] = [ ] <EOL> workflow_dict [ '<STR_LIT:status>' ] = <NUM_LIT:0> <EOL> workflow_dict [ '<STR_LIT>' ] = len ( workflow_dict [ '<STR_LIT>' ] ) <EOL> workflow_dict [ '<STR_LIT>' ] = { } <EOL> workflow_dict [ '<STR_LIT>' ] [ '<STR_LIT>' ] = [ ] <EOL> workflow_dict [ '<STR_LIT>' ] [ '<STR_LIT>' ] = [ ] <EOL> for step in workflow_dict [ '<STR_LIT>' ] : <EOL> workflow_dict [ '<STR_LIT>' ] += <NUM_LIT:1> <EOL> my_class = import_by_path ( step ) <EOL> my_instance = my_class ( ) <EOL> time_now = str ( time . strftime ( "<STR_LIT>" ) ) <EOL> msg = "<STR_LIT>" % ( <EOL> time_now , workflow_dict [ '<STR_LIT>' ] , workflow_dict [ '<STR_LIT>' ] , str ( my_instance ) ) <EOL> LOG . info ( msg ) <EOL> if task : <EOL> workflow_dict [ '<STR_LIT>' ] . append ( msg ) <EOL> task . update_details ( persist = True , details = msg ) <EOL> if my_instance . do ( workflow_dict ) != True : <EOL> workflow_dict [ '<STR_LIT:status>' ] = <NUM_LIT:0> <EOL> raise Exception ( <EOL> "<STR_LIT>" ) <EOL> workflow_dict [ '<STR_LIT:status>' ] = <NUM_LIT:1> <EOL> if task : <EOL> task . update_details ( persist = True , details = "<STR_LIT>" ) <EOL> workflow_dict [ '<STR_LIT>' ] = True <EOL> return True <EOL> except Exception : <EOL> if not workflow_dict [ '<STR_LIT>' ] [ '<STR_LIT>' ] or not workflow_dict [ '<STR_LIT>' ] [ '<STR_LIT>' ] : <EOL> traceback = full_stack ( ) <EOL> workflow_dict [ '<STR_LIT>' ] [ '<STR_LIT>' ] . append ( DBAAS_0001 ) <EOL> workflow_dict [ '<STR_LIT>' ] [ '<STR_LIT>' ] . append ( traceback ) <EOL> LOG . warn ( "<STR_LIT:\n>" . join ( "<STR_LIT>" . join ( error ) <EOL> for error in workflow_dict [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) ) <EOL> LOG . warn ( "<STR_LIT>" . join ( <EOL> workflow_dict [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) ) <EOL> workflow_dict [ '<STR_LIT>' ] = workflow_dict [ <EOL> '<STR_LIT>' ] [ : workflow_dict [ '<STR_LIT>' ] ] <EOL> stop_workflow ( workflow_dict , task ) <EOL> workflow_dict [ '<STR_LIT>' ] = False <EOL> return False <EOL> def stop_workflow ( workflow_dict , task = None ) : <EOL> LOG . info ( "<STR_LIT>" ) <EOL> if '<STR_LIT>' not in workflow_dict : <EOL> return False <EOL> if '<STR_LIT>' not in workflow_dict : <EOL> workflow_dict [ '<STR_LIT>' ] = { } <EOL> workflow_dict [ '<STR_LIT>' ] [ '<STR_LIT>' ] = [ ] <EOL> workflow_dict [ '<STR_LIT>' ] [ '<STR_LIT>' ] = [ ] <EOL> workflow_dict [ '<STR_LIT>' ] = len ( workflow_dict [ '<STR_LIT>' ] ) <EOL> if '<STR_LIT>' not in workflow_dict : <EOL> workflow_dict [ '<STR_LIT>' ] = len ( workflow_dict [ '<STR_LIT>' ] ) <EOL> workflow_dict [ '<STR_LIT>' ] = [ ] <EOL> workflow_dict [ '<STR_LIT>' ] = False <EOL> try : <EOL> for step in workflow_dict [ '<STR_LIT>' ] [ : : - <NUM_LIT:1> ] : <EOL> my_class = import_by_path ( step ) <EOL> my_instance = my_class ( ) <EOL> time_now = str ( time . strftime ( "<STR_LIT>" ) ) <EOL> msg = "<STR_LIT>" % ( <EOL> time_now , workflow_dict [ '<STR_LIT>' ] , workflow_dict [ '<STR_LIT>' ] , str ( my_instance ) ) <EOL> LOG . info ( msg ) <EOL> workflow_dict [ '<STR_LIT>' ] -= <NUM_LIT:1> <EOL> if task : <EOL> workflow_dict [ '<STR_LIT>' ] . append ( msg ) <EOL> task . update_details ( persist = True , details = msg ) <EOL> my_instance . undo ( workflow_dict ) <EOL> if task : <EOL> task . update_details ( persist = True , details = "<STR_LIT>" ) <EOL> return True <EOL> except Exception as e : <EOL> LOG . info ( "<STR_LIT>" . format ( e ) ) <EOL> if not workflow_dict [ '<STR_LIT>' ] [ '<STR_LIT>' ] or not workflow_dict [ '<STR_LIT>' ] [ '<STR_LIT>' ] : <EOL> traceback = full_stack ( ) <EOL> workflow_dict [ '<STR_LIT>' ] [ '<STR_LIT>' ] . append ( DBAAS_0001 ) <EOL> workflow_dict [ '<STR_LIT>' ] [ '<STR_LIT>' ] . append ( traceback ) <EOL> LOG . warn ( "<STR_LIT:\n>" . join ( "<STR_LIT>" . join ( error ) <EOL> for error in workflow_dict [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) ) <EOL> LOG . warn ( "<STR_LIT>" . join ( <EOL> workflow_dict [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) ) <EOL> return False </s>
