heavyai / pymapd

Python client for OmniSci GPU-accelerated SQL engine and analytics platform
https://pymapd.readthedocs.io/en/latest/
Apache License 2.0
111 stars 50 forks source link

Add auto-wakeup functionality to connect (OmniSci Cloud) #130

Open randyzwitch opened 5 years ago

randyzwitch commented 5 years ago

On the Community board, Veda posted an interesting solution for retrying to connect against OmniSci Cloud:

import time
from pymapd import connect

# Establish connection to MapD Cloud Instance
def connect_to_mapd(str_user, str_password, str_host, str_dbname):
 try:
   connection = connect(user=str_user, password=str_password, host=str_host, dbname=str_dbname, port=443, protocol='https')
 except Exception as ex:
   template = "An exception of type {0} occurred. Arguments:\n{1!r}"
   message = template.format(type(ex).__name__, ex.args)
   print(message)
   if 'OmniSci Core not ready, try again' in message:
     print("Set connection to RETRY!")
     connection = "RETRY"
   else:
     print("Set connection to ERROR!")
     connection = "ERROR"    

 return connection

We should incorporate this sort of functionality in pymapd.connect (after evaluating what is the correct way to do this, which may/may not be what Veda posted, as I haven't evaluated this code)

randyzwitch commented 5 years ago

@omveda Here's the issue I was talking about, it'd be great if you cleaned this up and submitted a PR