def _view_job(meth, job_id): """Views a job. :param job_id: A job id :type job_id: kbtypes.Unicode :ui_name job_id: A job id :rtype: kbtypes.Unicode :return: job info """ meth.stages = 2 meth.advance("Fetching job info") ujs = UserAndJobState(url=service.URLS.user_and_job_state, token=meth.token) job_info = ujs.get_job_info(job_id) meth.advance("Done!") return json.dumps(job_info)
def _view_job(meth, job_id): """Views a job. :param job_id: A job id :type job_id: kbtypes.Unicode :ui_name job_id: A job id :rtype: kbtypes.Unicode :return: job info """ meth.stages = 2 meth.advance("Fetching job info") ujs = UserAndJobState(url=service.URLS.user_and_job_state, token=meth.token) job_info = ujs.get_job_info(job_id) meth.advance("Done!") return json.dumps(job_info)
class NarrativeJobProxy: ''' Module Name: NarrativeJobProxy Module Description: Very simple proxy that reauthenticates requests to the user_and_job_state service as the narrative user. DO NOT DEPLOY PUBLICALLY ''' ######## WARNING FOR GEVENT USERS ####### # Since asynchronous IO can lead to methods - even the same method - # interrupting each other, you must be *very* careful when using global # state. A method could easily clobber the state set by another while # the latter method is running. ######################################### #BEGIN_CLASS_HEADER UPDATE_TOKEN_INTERVAL = 24 * 60 * 60 # 1 day in sec # UPDATE_TOKEN_INTERVAL = 10 def _update_token(self): if self._updating: return if (time.time() - self._updated_at < self.UPDATE_TOKEN_INTERVAL): return self._updating = True print('Updating token at ' + str(time.time())) try: self._ujs = UserAndJobState(self._url, user_id=self._user, password=self._pwd) self._updated_at = time.time() finally: # otherwise token will never be updated self._updating = False #END_CLASS_HEADER # config contains contents of config file in a hash or None if it couldn't # be found def __init__(self, config): #BEGIN_CONSTRUCTOR self._user = config.get('narrative_user') self._pwd = config.get('narrative_user_pwd') if not self._user or not self._pwd: raise ValueError( 'narrative user and/or narrative pwd missing from deploy.cfg') self._url = config.get('ujs_url') if not self._url: raise ValueError('UJS url missing from deploy.cfg') self._updated_at = - self.UPDATE_TOKEN_INTERVAL self._updating = False self._update_token() #END_CONSTRUCTOR pass def ver(self, ctx): # ctx is the context object # return variables are: ver #BEGIN ver ver = '0.0.1' #END ver # At some point might do deeper type checking... if not isinstance(ver, basestring): raise ValueError('Method ver return value ' + 'ver is not type basestring as required.') # return the results return [ver] def get_detailed_error(self, ctx, job): # ctx is the context object # return variables are: error #BEGIN get_detailed_error self._update_token() error = self._ujs.get_detailed_error(job) #END get_detailed_error # At some point might do deeper type checking... if not isinstance(error, basestring): raise ValueError('Method get_detailed_error return value ' + 'error is not type basestring as required.') # return the results return [error] def get_job_info(self, ctx, job): # ctx is the context object # return variables are: info #BEGIN get_job_info self._update_token() info = self._ujs.get_job_info(job) #END get_job_info # At some point might do deeper type checking... if not isinstance(info, list): raise ValueError('Method get_job_info return value ' + 'info is not type list as required.') # return the results return [info]
class NarrativeJobProxy: ''' Module Name: NarrativeJobProxy Module Description: Very simple proxy that reauthenticates requests to the user_and_job_state service as the narrative user. DO NOT DEPLOY PUBLICALLY ''' ######## WARNING FOR GEVENT USERS ####### # Since asynchronous IO can lead to methods - even the same method - # interrupting each other, you must be *very* careful when using global # state. A method could easily clobber the state set by another while # the latter method is running. ######################################### #BEGIN_CLASS_HEADER UPDATE_TOKEN_INTERVAL = 24 * 60 * 60 # 1 day in sec # UPDATE_TOKEN_INTERVAL = 10 def _update_token(self): if self._updating: return if (time.time() - self._updated_at < self.UPDATE_TOKEN_INTERVAL): return self._updating = True print('Updating token at ' + str(time.time())) try: self._ujs = UserAndJobState(self._url, user_id=self._user, password=self._pwd) self._updated_at = time.time() finally: # otherwise token will never be updated self._updating = False #END_CLASS_HEADER # config contains contents of config file in a hash or None if it couldn't # be found def __init__(self, config): #BEGIN_CONSTRUCTOR self._user = config.get('narrative_user') self._pwd = config.get('narrative_user_pwd') if not self._user or not self._pwd: raise ValueError( 'narrative user and/or narrative pwd missing from deploy.cfg') self._url = config.get('ujs_url') if not self._url: raise ValueError('UJS url missing from deploy.cfg') self._updated_at = -self.UPDATE_TOKEN_INTERVAL self._updating = False self._update_token() #END_CONSTRUCTOR pass def ver(self, ctx): # ctx is the context object # return variables are: ver #BEGIN ver ver = '0.0.1' #END ver # At some point might do deeper type checking... if not isinstance(ver, basestring): raise ValueError('Method ver return value ' + 'ver is not type basestring as required.') # return the results return [ver] def get_detailed_error(self, ctx, job): # ctx is the context object # return variables are: error #BEGIN get_detailed_error self._update_token() error = self._ujs.get_detailed_error(job) #END get_detailed_error # At some point might do deeper type checking... if not isinstance(error, basestring): raise ValueError('Method get_detailed_error return value ' + 'error is not type basestring as required.') # return the results return [error] def get_job_info(self, ctx, job): # ctx is the context object # return variables are: info #BEGIN get_job_info self._update_token() info = self._ujs.get_job_info(job) #END get_job_info # At some point might do deeper type checking... if not isinstance(info, list): raise ValueError('Method get_job_info return value ' + 'info is not type list as required.') # return the results return [info]
dest='showTimes', default=False) parser.add_argument('--ujs-url', help='url for user and job state service', action='store', dest='ujsURL', default='https://kbase.us/services/userandjobstate') usage = parser.format_usage() parser.description = desc1 + ' ' + usage + desc2 parser.usage = argparse.SUPPRESS args = parser.parse_args() # Get the status of the specified job. ujsClient = UserAndJobState(args.ujsURL) try: info = job_info_dict(ujsClient.get_job_info(args.jobID)) except JobStateServerError as e: print e.message exit(1) # Check if the job had an error. if info['error']: print "Job '%s' ended with error '%s' and no results are available." % ( args.jobID, info['status']) print 'Error details:' print ujsClient.get_detailed_error(args.jobID) ujsClient.delete_job(args.jobID) exit(1) # Check if the job is complete. if not info['complete']:
if __name__ == "__main__": # Parse options. parser = argparse.ArgumentParser(formatter_class=argparse.RawDescriptionHelpFormatter, prog='cbd-getmatrix', epilog=desc3) parser.add_argument('jobID', help='path to file with list of input sequence files', action='store', default=None) parser.add_argument('outputPath', help='path to output csv file', action='store', default=None) parser.add_argument('--show-times', help='show job start and end timestamps', action='store_true', dest='showTimes', default=False) parser.add_argument('--ujs-url', help='url for user and job state service', action='store', dest='ujsURL', default='https://kbase.us/services/userandjobstate') usage = parser.format_usage() parser.description = desc1 + ' ' + usage + desc2 parser.usage = argparse.SUPPRESS args = parser.parse_args() # Get the status of the specified job. ujsClient = UserAndJobState(args.ujsURL) try: info = job_info_dict(ujsClient.get_job_info(args.jobID)) except JobStateServerError as e: print e.message exit(1) # Check if the job had an error. if info['error']: print "Job '%s' ended with error '%s' and no results are available." %(args.jobID, info['status']) print 'Error details:' print ujsClient.get_detailed_error(args.jobID) ujsClient.delete_job(args.jobID) exit(1) # Check if the job is complete. if not info['complete']: print "Job '%s' has status '%s' and is working on task %s of %s. Check again later." \