-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathingestion_job.py
52 lines (42 loc) · 1.16 KB
/
ingestion_job.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
import boto3
import requests
import os
import asyncio
import aiohttp
import time
import random
start_time = time.time()
url = os.environ['URL']
print("URL " + url)
bucket = os.environ['BUCKET']
print("BUCKET " + bucket)
headers = {'Content-Type': 'application/json'}
timeout = aiohttp.ClientTimeout(total=79900)
client = boto3.client(
"s3"
)
async def post_request(file):
file = "s3://{0}/{1}".format(bucket, file)
data = {
"ingestion_id": "test",
"files": [file]
}
print("Sending " + str(data))
async with aiohttp.ClientSession(timeout=timeout) as session:
async with session.post(url, json = data, headers=headers, timeout=timeout) as resp:
data = await resp.text()
print ("Got Reply: " + data)
futures = []
index = 0
for key in client.list_objects(Bucket=bucket)['Contents']:
print(key['Key'])
file = key['Key']
futures.append(post_request(file))
if index >= 36:
print("waiting...")
index = 0
index += 1
loop = asyncio.get_event_loop()
loop.run_until_complete(asyncio.wait(futures))
print("Took %s" % (time.time() - start_time))
print("Completed!")