Skip to content

Instantly share code, notes, and snippets.

@alex4u2nv
Last active September 23, 2021 19:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alex4u2nv/6bf21dcb0352cecbcee188b1bc649aeb to your computer and use it in GitHub Desktop.
Save alex4u2nv/6bf21dcb0352cecbcee188b1bc649aeb to your computer and use it in GitHub Desktop.
worker.py
#! /usr/bin/env python3
import boto3
import time
import os
REGION = os.getenv('AWS_REGION', 'us-east-1')
def fibonacci(n):
if n <= 0:
print("incorect input")
elif n == 1:
return 0
elif n==2:
return 1
else:
return fibonacci(n-1)+fibonacci(n-2)
if __name__ == "__main__":
sqs = boto3.resource('sqs', region_name=REGION)
# Get the queue
queue = sqs.get_queue_by_name(QueueName='Expense-Report-Queue')
count = 0
while True:
count = 1 + count
print("while loop: ", count)
for message in queue.receive_messages(MessageAttributeNames=['All'], MaxNumberOfMessages=10):
print("processing message on sqs")
number_text='0'
if message.message_attributes is not None:
number = (message.message_attributes.get('Fibonacci').get('StringValue'))
if number:
number_text = '{0}'.format(number)
number = int(number)
print(fibonacci(number))
print('{0}{1}'.format(message.body, number_text))
print('deleting message', count)
message.delete()
time.sleep(2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment