in textract-pipeline/lambda/asyncprocessor/lambda_function.py [0:0]
def processRequest(request):
qUrl = request['qUrl']
snsTopic = request['snsTopic']
snsRole = request['snsRole']
i = 0
max = 100
totalJobsScheduled = 0
hitLimit = False
provisionedThroughputExceededCount = 0
while(i < max):
try:
tc, jc = processItems(qUrl, snsTopic, snsRole)
totalJobsScheduled += jc
if(tc == 0):
i = max
except Exception as e:
if(e.__class__.__name__ == 'LimitExceededException'):
print("Exception: Hit limit.")
hitLimit = True
i = max
elif(e.__class__.__name__ == "ProvisionedThroughputExceededException"):
print("ProvisionedThroughputExceededException.")
provisionedThroughputExceededCount += 1
if(provisionedThroughputExceededCount > 5):
i = max
else:
print("Waiting for few seconds...")
time.sleep(5)
print("Waking up...")
i += 1
output = "Started {} jobs.".format(totalJobsScheduled)
if(hitLimit):
output += " Hit limit."
print(output)
return {
'statusCode': 200,
'body': output
}