-
Notifications
You must be signed in to change notification settings - Fork 20
/
extend_queue.py
38 lines (31 loc) · 968 Bytes
/
extend_queue.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
import os
import sys
import boto3
import hashlib
def main():
URL = os.environ['TADPOLES_SQS_QUEUE_URL']
client = boto3.client('sqs')
with open(sys.argv[1]) as f:
done = False
while True:
entries = []
for i in range(10):
try:
body = next(f)
except StopIteration:
done = True
break
entries.append(dict(
Id=hashlib.md5(bytes(body, 'utf8')).hexdigest(),
MessageBody=body
))
response = client.send_message_batch(
QueueUrl=URL,
Entries=entries
)
if response['ResponseMetadata']['HTTPStatusCode'] != 200:
raise Exception('Bad response: %r' % response)
if done:
break
if __name__ == "__main__":
main()