<s> from taskflow import exceptions as exc <EOL> CLAIMED = '<STR_LIT>' <EOL> COMPLETE = '<STR_LIT>' <EOL> UNCLAIMED = '<STR_LIT>' <EOL> FAILURE = '<STR_LIT>' <EOL> PENDING = '<STR_LIT>' <EOL> REVERTING = '<STR_LIT>' <EOL> REVERTED = '<STR_LIT>' <EOL> RUNNING = '<STR_LIT>' <EOL> SUCCESS = '<STR_LIT>' <EOL> SUSPENDING = '<STR_LIT>' <EOL> SUSPENDED = '<STR_LIT>' <EOL> RESUMING = '<STR_LIT>' <EOL> FAILURE = FAILURE <EOL> PENDING = PENDING <EOL> REVERTED = REVERTED <EOL> REVERTING = REVERTING <EOL> SUCCESS = SUCCESS <EOL> RUNNING = RUNNING <EOL> RETRYING = '<STR_LIT>' <EOL> IGNORE = '<STR_LIT>' <EOL> REVERT_FAILURE = '<STR_LIT>' <EOL> EXECUTE = '<STR_LIT>' <EOL> IGNORE = IGNORE <EOL> REVERT = '<STR_LIT>' <EOL> RETRY = '<STR_LIT>' <EOL> INTENTIONS = ( EXECUTE , IGNORE , REVERT , RETRY ) <EOL> SCHEDULING = '<STR_LIT>' <EOL> WAITING = '<STR_LIT>' <EOL> ANALYZING = '<STR_LIT>' <EOL> _ALLOWED_JOB_TRANSITIONS = frozenset ( ( <EOL> ( UNCLAIMED , CLAIMED ) , <EOL> ( CLAIMED , UNCLAIMED ) , <EOL> ( CLAIMED , COMPLETE ) , <EOL> ) ) <EOL> def check_job_transition ( old_state , new_state ) : <EOL> """<STR_LIT>""" <EOL> if old_state == new_state : <EOL> return False <EOL> pair = ( old_state , new_state ) <EOL> if pair in _ALLOWED_JOB_TRANSITIONS : <EOL> return True <EOL> raise exc . InvalidState ( "<STR_LIT>" <EOL> % pair ) <EOL> _ALLOWED_FLOW_TRANSITIONS = frozenset ( ( <EOL> ( PENDING , RUNNING ) , <EOL> ( RUNNING , SUCCESS ) , <EOL> ( RUNNING , FAILURE ) , <EOL> ( RUNNING , REVERTED ) , <EOL> ( RUNNING , SUSPENDING ) , <EOL> ( RUNNING , RESUMING ) , <EOL> ( SUCCESS , RUNNING ) , <EOL> ( FAILURE , RUNNING ) , <EOL> ( REVERTED , PENDING ) , <EOL> ( SUCCESS , PENDING ) , <EOL> ( SUSPENDING , SUSPENDED ) , <EOL> ( SUSPENDING , SUCCESS ) , <EOL> ( SUSPENDING , FAILURE ) , <EOL> ( SUSPENDING , REVERTED ) , <EOL> ( SUSPENDING , RESUMING ) , <EOL> ( SUSPENDED , RUNNING ) , <EOL> ( RESUMING , SUSPENDED ) , <EOL> ) ) <EOL> _IGNORED_FLOW_TRANSITIONS = frozenset ( <EOL> ( a , b ) <EOL> for a in ( PENDING , FAILURE , SUCCESS , SUSPENDED , REVERTED ) <EOL> for b in ( SUSPENDING , SUSPENDED , RESUMING ) <EOL> if a != b <EOL> ) <EOL> def check_flow_transition ( old_state , new_state ) : <EOL> """<STR_LIT>""" <EOL> if old_state == new_state : <EOL> return False <EOL> pair = ( old_state , new_state ) <EOL> if pair in _ALLOWED_FLOW_TRANSITIONS : <EOL> return True <EOL> if pair in _IGNORED_FLOW_TRANSITIONS : <EOL> return False <EOL> raise exc . InvalidState ( "<STR_LIT>" <EOL> % pair ) <EOL> _ALLOWED_TASK_TRANSITIONS = frozenset ( ( <EOL> ( PENDING , RUNNING ) , <EOL> ( PENDING , IGNORE ) , <EOL> ( RUNNING , SUCCESS ) , <EOL> ( RUNNING , FAILURE ) , <EOL> ( FAILURE , REVERTING ) , <EOL> ( SUCCESS , REVERTING ) , <EOL> ( REVERTING , REVERTED ) , <EOL> ( REVERTING , REVERT_FAILURE ) , <EOL> ( REVERTED , PENDING ) , <EOL> ( IGNORE , PENDING ) , <EOL> ) ) <EOL> def check_task_transition ( old_state , new_state ) : <EOL> """<STR_LIT>""" <EOL> pair = ( old_state , new_state ) <EOL> if pair in _ALLOWED_TASK_TRANSITIONS : <EOL> return True <EOL> return False <EOL> _ALLOWED_RETRY_TRANSITIONS = list ( _ALLOWED_TASK_TRANSITIONS ) <EOL> _ALLOWED_RETRY_TRANSITIONS . extend ( [ <EOL> ( SUCCESS , RETRYING ) , <EOL> ( RETRYING , RUNNING ) , <EOL> ] ) <EOL> _ALLOWED_RETRY_TRANSITIONS = frozenset ( _ALLOWED_RETRY_TRANSITIONS ) <EOL> def check_retry_transition ( old_state , new_state ) : <EOL> """<STR_LIT>""" <EOL> pair = ( old_state , new_state ) <EOL> if pair in _ALLOWED_RETRY_TRANSITIONS : <EOL> return True <EOL> return False </s>
