<s> from memsql_loader . api . base import Api <EOL> from memsql_loader . api import shared , exceptions <EOL> from memsql_loader . api . validation import V <EOL> class Job ( Api ) : <EOL> name = '<STR_LIT>' <EOL> validate = V . Schema ( { <EOL> V . Required ( '<STR_LIT>' ) : basestring <EOL> } ) <EOL> def _execute ( self , params ) : <EOL> generated_sql , query_params = self . _generate_sql ( params ) <EOL> row = self . _db_query ( """<STR_LIT>""" % generated_sql , ** query_params ) <EOL> if len ( row ) == <NUM_LIT:0> : <EOL> raise exceptions . ApiException ( '<STR_LIT>' % params [ '<STR_LIT>' ] ) <EOL> elif len ( row ) > <NUM_LIT:1> : <EOL> raise exceptions . ApiException ( '<STR_LIT>' % params [ '<STR_LIT>' ] ) <EOL> row = row [ <NUM_LIT:0> ] <EOL> return shared . job_load_row ( row ) <EOL> def _generate_sql ( self , params ) : <EOL> query_params = shared . TaskState . projection_params ( ) <EOL> return { <EOL> '<STR_LIT>' : shared . TaskState . SUCCESS_CONDITION , <EOL> '<STR_LIT>' : shared . TaskState . ERROR_CONDITION , <EOL> '<STR_LIT>' : shared . TaskState . CANCELLED_CONDITION , <EOL> '<STR_LIT>' : shared . TaskState . FINISHED_CONDITION , <EOL> '<STR_LIT>' : shared . TaskState . QUEUED_CONDITION , <EOL> '<STR_LIT>' : shared . JobState . PROJECTION , <EOL> '<STR_LIT>' : self . _task_job_id_predicate ( params , query_params ) , <EOL> '<STR_LIT>' : self . _job_id_predicate ( params , query_params ) <EOL> } , query_params <EOL> def _task_job_id_predicate ( self , params , query_params ) : <EOL> query_params [ '<STR_LIT>' ] = params [ '<STR_LIT>' ] + '<STR_LIT:%>' <EOL> return '<STR_LIT>' <EOL> def _job_id_predicate ( self , params , query_params ) : <EOL> query_params [ '<STR_LIT>' ] = params [ '<STR_LIT>' ] + '<STR_LIT:%>' <EOL> return '<STR_LIT>' </s>
