Last active
May 19, 2023 18:37
-
-
Save apetenchea/0d686629e675119bfed1571ddf1ebe93 to your computer and use it in GitHub Desktop.
Using async jobs in python-arango
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import arango | |
import time | |
url = f"http://localhost:8530" | |
client = arango.ArangoClient(hosts=url) | |
db = client.db(name="_system") | |
print(db.version()) | |
if not db.has_collection('x'): | |
db.create_collection('x') | |
x = db.collection('x') | |
async_db = db.begin_async_execution(return_result=True) | |
async_aql = async_db.aql | |
job1 = async_aql.execute(""" | |
FOR i IN 1..50000 | |
INSERT {bar: i} INTO @@c1 | |
""", bind_vars={'@c1': 'x'}) | |
print('job1') | |
print(job1.id) | |
print(job1.id) | |
print(db.async_jobs('pending', count=100)) | |
print(db.async_jobs('pending', count=100)) | |
print(db.async_jobs('pending', count=100)) | |
print(db.async_jobs('pending', count=100)) | |
# For fun, ask for the same thing, but using an async request | |
# Notice that job.result() should include both the ids of job1 and job2 | |
print('job2') | |
job2 = async_db.async_jobs('pending', count=100) | |
print(job2.id) | |
print(job2.result()) | |
print('waiting for job1') | |
while job1.status() != 'done': | |
print(job1.status()) | |
time.sleep(1) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment