Skip to content
This repository was archived by the owner on May 23, 2023. It is now read-only.

Commit 9d014ac

Browse files
tratativas localhost/docker
1 parent 2ca7b51 commit 9d014ac

File tree

6 files changed

+34
-6
lines changed

6 files changed

+34
-6
lines changed

examples/lambda_api/lambda_app/database/mysql.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,10 @@ def get_connection(config=None, connect=True, retry=False):
5656
_RETRY_COUNT += 1
5757
# Fix para tratar diff entre docker/local
5858
if config.DB_HOST == 'mysql':
59+
old_value = config.DB_HOST
5960
config.DB_HOST = 'localhost'
61+
logger.info(
62+
'Changing the endpoint from {} to {}'.format(old_value, config.DB_HOST))
6063
return get_connection(config, True)
6164
else:
6265
connection = _CONNECTION

examples/lambda_sqs/lambda_app/database/mysql.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,10 @@ def get_connection(config=None, connect=True, retry=False):
5656
_RETRY_COUNT += 1
5757
# Fix para tratar diff entre docker/local
5858
if config.DB_HOST == 'mysql':
59+
old_value = config.DB_HOST
5960
config.DB_HOST = 'localhost'
61+
logger.info(
62+
'Changing the endpoint from {} to {}'.format(old_value, config.DB_HOST))
6063
return get_connection(config, True)
6164
else:
6265
connection = _CONNECTION

examples/lambda_sqs/lambda_app/services/v1/carrier_notifier_service.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ def get_records_from_sqs_event(self, sqs_event):
8080
records = []
8181
try:
8282
if isinstance(sqs_event, SQSEvent):
83+
self.logger.info("SQSEvent instance")
8384
if not helper.empty(sqs_event.to_dict()):
8485
try:
8586
sqs_event_dict = sqs_event.to_dict()
@@ -91,6 +92,7 @@ def get_records_from_sqs_event(self, sqs_event):
9192
self.logger.error(err)
9293
records.append(sqs_event.to_dict())
9394
elif isinstance(sqs_event, SQSRecord):
95+
self.logger.info("SQSRecord instance")
9496
if not helper.empty(sqs_event.to_dict()):
9597
records.append(sqs_event)
9698
except Exception as err:
Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,23 @@
11
{
2-
"chavenfe": "32210206107255000134550010001712551245826554",
3-
"ocor": "MOTIVO DO CANCELAMENTO",
4-
"origem": "SAC/EAGLE",
5-
"pedido": "Z1223321"
2+
"Records": [
3+
{
4+
"messageId": "11d6ee51-4cc7-4302-9e22-7cd8afdaadf5",
5+
"receiptHandle": "AQEBBX8nesZEXmkhsmZeyIE8iQAMig7qw...",
6+
"body": "{\n \"chavenfe\": \"32210206107255000134550010001712551245826554\",\n \"ocor\": \"MOTIVO DO CANCELAMENTO\",\n \"origem\": \"SAC/EAGLE\",\n \"pedido\": \"Z1223321\"\n}",
7+
"attributes": {
8+
"ApproximateReceiveCount": "1",
9+
"SentTimestamp": "1573251510774",
10+
"SequenceNumber": "18849496460467696128",
11+
"MessageGroupId": "1",
12+
"SenderId": "AIDAIO23YVJENQZJOL4VO",
13+
"MessageDeduplicationId": "1",
14+
"ApproximateFirstReceiveTimestamp": "1573251510774"
15+
},
16+
"messageAttributes": {},
17+
"md5OfBody": "e4e68fb7bd0e697a0ae8f1bb342846b3",
18+
"eventSource": "aws:sqs",
19+
"eventSourceARN": "arn:aws:sqs:us-east-2:683720833731:fretzy-delivery-time-simulator-queue.fifo",
20+
"awsRegion": "us-east-2"
21+
}
22+
]
623
}

examples/lambda_sqs/tests/component/test_app.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import os
22
import unittest
3+
from time import sleep
34

45
from tests.component.componenttestutils import BaseComponentTestCase
56
from lambda_app import helper
@@ -31,6 +32,7 @@ def get_queue_events_samples():
3132

3233
# AttributeError: module 'typing' has no attribute '_classvar'
3334
# This error occours on Python 3.8
35+
# If you will consume items from the queue, dont boot the lambda
3436
class AppTestCase(BaseComponentTestCase):
3537
"""
3638
@@ -74,6 +76,7 @@ def fixture_sqs(cls, logger, queue_url):
7476
SQSHelper.create_message(message, queue_url)
7577
logger.info('created message: {}'.format(message))
7678
# message = SQSHelper.get_message(queue_url)
79+
# logger.info('reading message: {}'.format(message))
7780
# print(message)
7881

7982
@data_provider(get_queue_message)

examples/lambda_sqs/tests/component/test_lambda_app/services/v1/test_carrier_notifier_service.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ def get_queue_message():
2020
queue_url = os.getenv("APP_QUEUE")
2121
event = SQSHelper.get_message(queue_url)
2222

23-
return (event,)
23+
return (event,),
2424

2525

2626
def get_queue_events_samples():
2727
event = get_cancelamento_event()
2828
sqs_event = create_chalice_sqs_event(event)
2929

30-
return (sqs_event,)
30+
return (sqs_event,),
3131

3232

3333
class CarrierNotifierServiceTestCase(BaseComponentTestCase):

0 commit comments

Comments
 (0)