in src/graph_notebook/magics/graph_magic.py [0:0]
def handle_opencypher_status(self, line, local_ns):
"""
This is refactored into its own handler method so that we can invoke it from
%opencypher_status or from %oc_status
"""
parser = argparse.ArgumentParser()
parser.add_argument('-q', '--queryId', default='',
help='The ID of a running OpenCypher query. '
'Only displays the status of the specified query.')
parser.add_argument('-c', '--cancelQuery', action='store_true', default=False,
help='Tells the status command to cancel a query. This parameter does not take a value.')
parser.add_argument('-w', '--includeWaiting', action='store_true', default=False,
help='Neptune DB only. When set to true and other parameters are not present, causes '
'status information for waiting queries to be returned as well as for running '
'queries. This parameter does not take a value.')
parser.add_argument('--state', type=str.upper, default='ALL',
help=f'Neptune Analytics only. Specifies what subset of query states to retrieve the '
f'status of. Default is ALL. Accepted values: {OPENCYPHER_STATUS_STATE_MODES}')
parser.add_argument('-m', '--maxResults', type=int, default=200,
help=f'Neptune Analytics only. Sets an upper limit on the set of returned queries whose '
f'status matches --state. Default is 200.')
parser.add_argument('-s', '--silent-cancel', action='store_true', default=False,
help='If silent_cancel=true then the running query is cancelled and the HTTP response '
'code is 200. If silent_cancel is not present or silent_cancel=false, '
'the query is cancelled with an HTTP 500 status code.')
parser.add_argument('--silent', action='store_true', default=False, help="Display no output.")
parser.add_argument('--store-to', type=str, default='', help='store query result to this variable')
args = parser.parse_args(line.split())
using_analytics = self.client.is_analytics_domain()
if not args.cancelQuery:
query_id = ''
include_waiting = None
state = ''
max_results = None
if args.includeWaiting and not args.queryId and not self.client.is_analytics_domain():
include_waiting = args.includeWaiting
elif args.state and not args.queryId and self.client.is_analytics_domain():
state = args.state
max_results = args.maxResults
else:
query_id = args.queryId
res = self.client.opencypher_status(query_id=query_id,
include_waiting=include_waiting,
state=state,
max_results=max_results,
use_analytics_endpoint=using_analytics)
if using_analytics and res.status_code == 400 and 'Bad route: /queries' in res.json()["message"]:
res = self.client.opencypher_status(query_id=query_id,
include_waiting=include_waiting,
state=state,
max_results=max_results,
use_analytics_endpoint=False)
res.raise_for_status()
else:
if args.queryId == '':
if not args.silent:
print(OPENCYPHER_CANCEL_HINT_MSG)
return
else:
res = self.client.opencypher_cancel(args.queryId,
silent=args.silent_cancel,
use_analytics_endpoint=using_analytics)
if using_analytics and res.status_code == 400 and 'Bad route: /queries' in res.json()["message"]:
res = self.client.opencypher_cancel(args.queryId,
silent=args.silent_cancel,
use_analytics_endpoint=False)
res.raise_for_status()
if using_analytics and args.cancelQuery:
if not args.silent:
print(f'Submitted cancellation request for query ID: {args.queryId}')
else:
js = res.json()
store_to_ns(args.store_to, js, local_ns)
if not args.silent:
print(json.dumps(js, indent=2))