def wrapper(*args, **kwargs): message = "Whoa, you found a bug." try: return func(*args, **kwargs) except requests.HTTPError as err: raise CommError(err.response, err) except RetryError as err: if "response" in dir(err.last_exception ) and err.last_exception.response is not None: try: message = err.last_exception.response.json().get( 'errors', [{ 'message': message }])[0]['message'] except ValueError: message = err.last_exception.response.text else: message = err.last_exception if env.is_debug(): six.reraise(type(err.last_exception), err.last_exception, sys.exc_info()[2]) else: six.reraise(CommError, CommError(message, err.last_exception), sys.exc_info()[2]) except Exception as err: # gql raises server errors with dict's as strings... if len(err.args) > 0: payload = err.args[0] else: payload = err if str(payload).startswith("{"): message = ast.literal_eval(str(payload))["message"] else: message = str(err) if env.is_debug(): six.reraise(*sys.exc_info()) else: six.reraise(CommError, CommError(message, err), sys.exc_info()[2])
def upsert_run(self, id=None, name=None, project=None, host=None, group=None, tags=None, config=None, description=None, entity=None, state=None, display_name=None, notes=None, repo=None, job_type=None, program_path=None, commit=None, sweep_name=None, summary_metrics=None, num_retries=None): """Update a run Args: id (str, optional): The existing run to update name (str, optional): The name of the run to create group (str, optional): Name of the group this run is a part of project (str, optional): The name of the project config (dict, optional): The latest config params description (str, optional): A description of this project entity (str, optional): The entity to scope this project to. repo (str, optional): Url of the program's repository. state (str, optional): State of the program. job_type (str, optional): Type of job, e.g 'train'. program_path (str, optional): Path to the program. commit (str, optional): The Git SHA to associate the run with summary_metrics (str, optional): The JSON summary metrics """ mutation = gql(''' mutation UpsertBucket( $id: String, $name: String, $project: String, $entity: String!, $groupName: String, $description: String, $displayName: String, $notes: String, $commit: String, $config: JSONString, $host: String, $debug: Boolean, $program: String, $repo: String, $jobType: String, $state: String, $sweep: String, $tags: [String!], $summaryMetrics: JSONString, ) { upsertBucket(input: { id: $id, name: $name, groupName: $groupName, modelName: $project, entityName: $entity, description: $description, displayName: $displayName, notes: $notes, config: $config, commit: $commit, host: $host, debug: $debug, jobProgram: $program, jobRepo: $repo, jobType: $jobType, state: $state, sweep: $sweep, tags: $tags, summaryMetrics: $summaryMetrics, }) { bucket { id name displayName description config project { id name entity { id name } } } } } ''') if config is not None: config = json.dumps(config) if not description or description.isspace(): description = None kwargs = {} if num_retries is not None: kwargs['num_retries'] = num_retries variable_values = { 'id': id, 'entity': entity or self.settings('entity'), 'name': name, 'project': project, 'groupName': group, 'tags': tags, 'description': description, 'config': config, 'commit': commit, 'displayName': display_name, 'notes': notes, 'host': None if self.settings().get('anonymous') == 'true' else host, 'debug': env.is_debug(env=self._environ), 'repo': repo, 'program': program_path, 'jobType': job_type, 'state': state, 'sweep': sweep_name, 'summaryMetrics': summary_metrics } response = self.gql( mutation, variable_values=variable_values, **kwargs) run = response['upsertBucket']['bucket'] project = run.get('project') if project: self.set_setting('project', project['name']) entity = project.get('entity') if entity: self.set_setting('entity', entity['name']) return response['upsertBucket']['bucket']
def upsert_run( self, id=None, name=None, project=None, host=None, group=None, tags=None, config=None, description=None, entity=None, state=None, display_name=None, notes=None, repo=None, job_type=None, program_path=None, commit=None, sweep_name=None, summary_metrics=None, num_retries=None, ): """Update a run Arguments: id (str, optional): The existing run to update name (str, optional): The name of the run to create group (str, optional): Name of the group this run is a part of project (str, optional): The name of the project config (dict, optional): The latest config params description (str, optional): A description of this project entity (str, optional): The entity to scope this project to. repo (str, optional): Url of the program's repository. state (str, optional): State of the program. job_type (str, optional): Type of job, e.g 'train'. program_path (str, optional): Path to the program. commit (str, optional): The Git SHA to associate the run with summary_metrics (str, optional): The JSON summary metrics """ mutation = gql(""" mutation UpsertBucket( $id: String, $name: String, $project: String, $entity: String!, $groupName: String, $description: String, $displayName: String, $notes: String, $commit: String, $config: JSONString, $host: String, $debug: Boolean, $program: String, $repo: String, $jobType: String, $state: String, $sweep: String, $tags: [String!], $summaryMetrics: JSONString, ) { upsertBucket(input: { id: $id, name: $name, groupName: $groupName, modelName: $project, entityName: $entity, description: $description, displayName: $displayName, notes: $notes, config: $config, commit: $commit, host: $host, debug: $debug, jobProgram: $program, jobRepo: $repo, jobType: $jobType, state: $state, sweep: $sweep, tags: $tags, summaryMetrics: $summaryMetrics, }) { bucket { id name displayName description config project { id name entity { id name } } } } } """) if config is not None: config = json.dumps(config) if not description or description.isspace(): description = None kwargs = {} if num_retries is not None: kwargs["num_retries"] = num_retries variable_values = { "id": id, "entity": entity or self.settings("entity"), "name": name, "project": project, "groupName": group, "tags": tags, "description": description, "config": config, "commit": commit, "displayName": display_name, "notes": notes, "host": None if self.settings().get("anonymous") == "true" else host, "debug": env.is_debug(env=self._environ), "repo": repo, "program": program_path, "jobType": job_type, "state": state, "sweep": sweep_name, "summaryMetrics": summary_metrics, } response = self.gql(mutation, variable_values=variable_values, **kwargs) run = response["upsertBucket"]["bucket"] project = run.get("project") if project: self.set_setting("project", project["name"]) entity = project.get("entity") if entity: self.set_setting("entity", entity["name"]) return response["upsertBucket"]["bucket"]