-
Notifications
You must be signed in to change notification settings - Fork 0
/
data_load_per_x_page.py
58 lines (49 loc) · 2.25 KB
/
data_load_per_x_page.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import gremlin_base_functions as gf
import data_load_data_per_x_page as dld
from gremlin_python.driver import client, serializer, protocol
from gremlin_python.driver.protocol import GremlinServerError
import sys
import traceback
import time
try:
client = gf.connect()
for query in dld._gremlin_insert_edges:
print("\n> {0}\n".format(query))
# don't go too fast. Wait. Avoid "Request rate is large. More Request Units may be needed, so no changes were made. Please retry this request later. Learn more: http://aka.ms/cosmosdb-error-429"
time.sleep(1)
callback = client.submitAsync(query)
if callback.result() is not None:
print("\tInserted this edge:\n\t{0}".format(
callback.result().all().result()))
else:
print("Something went wrong with this query: {0}".format(query))
print("\n")
gf.print_status_attributes(callback.result())
print("\n")
time.sleep(1)
client.close()
except GremlinServerError as e:
print('Code: {0}, Attributes: {1}'.format(e.status_code, e.status_attributes))
# GremlinServerError.status_code returns the Gremlin protocol status code
# These are broad status codes which can cover various scenaios, so for more specific
# error handling we recommend using GremlinServerError.status_attributes['x-ms-status-code']
#
# Below shows how to capture the Cosmos DB specific status code and perform specific error handling.
# See detailed set status codes than can be returned here: https://docs.microsoft.com/en-us/azure/cosmos-db/gremlin-headers#status-codes
#
# See also list of available response status attributes that Gremlin API can return:
# https://docs.microsoft.com/en-us/azure/cosmos-db/gremlin-headers#headers
cosmos_status_code = e.status_attributes["x-ms-status-code"]
if cosmos_status_code == 409:
print('Conflict error!')
elif cosmos_status_code == 412:
print('Precondition error!')
elif cosmos_status_code == 429:
print('Throttling error!');
elif cosmos_status_code == 1009:
print('Request timeout error!')
else:
print("Default error handling")
traceback.print_exc(file=sys.stdout)
sys.exit(1)
print("\nComplete")