Last active
February 1, 2023 23:08
-
-
Save gungoren/0d1e19e076607384bec3cf7c9a78b1f2 to your computer and use it in GitHub Desktop.
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 os | |
import boto3 | |
from time import sleep | |
sqs = boto3.client('sqs') | |
queue_url = os.getenv("QUEUE_URL") | |
def fib(num): | |
if num <= 1: | |
return 1 | |
return fib(num - 1) + fib(num - 2) | |
if __name__ == '__main__': | |
while True: | |
try: | |
response = sqs.receive_message( | |
QueueUrl=queue_url, | |
AttributeNames=['SentTimestamp'], | |
MaxNumberOfMessages=1, | |
MessageAttributeNames=['All'], | |
VisibilityTimeout=10, | |
WaitTimeSeconds=10 | |
) | |
if 'Messages' in response: | |
message = response['Messages'][0] | |
receipt_handle = message['ReceiptHandle'] | |
msg = message['Body'] | |
print(f"{msg} => {fib(int(msg))}") | |
sqs.delete_message(QueueUrl=queue_url, ReceiptHandle=receipt_handle) | |
sleep(2) | |
except: | |
print('Queue empty') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment