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

Commit 043f0c0

Browse files
Ajustes para rodar subir e executar toda a stack
1 parent 77b86e2 commit 043f0c0

File tree

24 files changed

+282
-61
lines changed

24 files changed

+282
-61
lines changed

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ services:
3737
expose:
3838
- 6379
3939
networks:
40-
- default
40+
- service-python
4141
mysql:
4242
image: mysql:5.7.22
4343
ports:

examples/lambda_api/docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ services:
2323
expose:
2424
- 6379
2525
networks:
26-
- default
26+
- service-python
2727
mysql:
2828
image: mysql:5.7.22
2929
ports:

examples/lambda_api/env/development.env

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@ APP_ENV=development
33
DEBUG=true
44
LOG_LEVEL=info
55
REGION_NAME=us-east-1
6-
SQS_ENDPOINT=http://0.0.0.0:4566
7-
SQS_LOCALSTACK=http://0.0.0.0:4566
8-
APP_QUEUE=http://0.0.0.0:4566/000000000000/test-queue
6+
SQS_ENDPOINT=http://localstack:4566
7+
SQS_LOCALSTACK=http://localstack:4566
8+
APP_QUEUE=http://localstack:4566/000000000000/test-queue
99
API_SERVER=http://localhost:5000
1010
API_SERVER_DESCRIPTION=Staging server
1111
LOCAL_API_SERVER=http://localhost:5000
1212
LOCAL_API_SERVER_DESCRIPTION=Development server
1313
REDIS_HOST=redis
1414
REDIS_PORT=6379
15-
DB_HOST = localhost
15+
DB_HOST = mysql
1616
DB_USER = root
1717
DB_PASSWORD = store
1818
DB = store

examples/lambda_api/lambda_app/events/aws/sqs.py

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import json
22
import os
33

4+
from lambda_app import helper
45
from lambda_app.config import get_config
56
from lambda_app.logging import get_logger
67
import boto3
78

9+
_RETRY_COUNT = 0
10+
_MAX_RETRY_ATTEMPTS = 3
811

912
class SQSEvents:
1013

@@ -16,7 +19,8 @@ def __init__(self, logger=None, config=None):
1619
# last_exception
1720
self.exception = None
1821

19-
def connect(self):
22+
def connect(self, retry=False):
23+
global _RETRY_COUNT, _MAX_RETRY_ATTEMPTS
2024
connection = None
2125
try:
2226
endpoint_url = self.config.SQS_ENDPOINT
@@ -38,11 +42,32 @@ def connect(self):
3842
region_name=self.config.REGION_NAME
3943
)
4044

41-
self.logger.info('SQSEvents - Connected')
45+
try:
46+
connection.get_queue_by_name(QueueName='test')
47+
except Exception as err:
48+
if helper.has_attr(err, "response") and err.response['Error']:
49+
self.logger.info('SQSEvents - Connected')
50+
else:
51+
raise err
4252

43-
except Exception as err:
44-
self.logger.error(err)
53+
_CONNECTION = connection
54+
_RETRY_COUNT = 0
4555

56+
except Exception as err:
57+
if _RETRY_COUNT == _MAX_RETRY_ATTEMPTS:
58+
_RETRY_COUNT = 0
59+
self.logger.error(err)
60+
connection = None
61+
else:
62+
self.logger.error(err)
63+
self.logger.info('Trying to reconnect... {}'.format(_RETRY_COUNT))
64+
# retry
65+
if not retry:
66+
_RETRY_COUNT += 1
67+
# Fix para tratar diff entre docker/local
68+
if self.config.SQS_ENDPOINT == 'http://0.0.0.0:4566' or self.config.SQS_ENDPOINT == 'http://localstack:4566':
69+
self.config.DB_HOST = 'http://localhost:4566'
70+
connection = self.connect(retry=True)
4671
return connection
4772

4873
def send_message(self, message, queue_url):
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#echo 'Booting database...'
2+
## TODO futuramente usar o Flask migrate ou outra alternativa
3+
#
4+
#echo 'Creating tables...'
5+
#python3 ./scripts/migrations/mysql/migrate.py ./tests/datasets/database/structure/mysql/create.table.store.ocorens.sql
6+
#python3 ./scripts/migrations/mysql/migrate.py ./tests/datasets/database/structure/mysql/create.table.store.products.sql
7+
#
8+
#echo 'Inserting data in the table...'
9+
#python3 ./scripts/migrations/mysql/migrate.py ./tests/datasets/database/seeders/mysql/seeder.table.store.ocorens.sql
10+
#python3 ./scripts/migrations/mysql/migrate.py ./tests/datasets/database/seeders/mysql/seeder.table.store.products.sql
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
echo 'Booting lambda...'
2+
echo 'Installing dependencies...'
3+
# ./scripts/venv.sh
4+
python3 -m pip install -r ./requirements.txt -t ./vendor
5+
python3 -m pip install -r ./requirements-vendor.txt -t ./vendor
6+
7+
echo 'Creating resource dependencies...'
8+
# create resource dependencies
9+
./scripts/localstack/lambda/create-function-from-s3.sh lambda_sqs
10+
#./scripts/localstack/lambda/create-event-source-mapping.sh lambda_sqs test-queue
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
./scripts/localstack/sqs/create-queue.sh test-queue
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/bash
2+
echo 'Validating jd installation..'
3+
/usr/bin/jq --help > /dev/null 2>&1
4+
if [ $? -ne 0 ]; then
5+
echo 'Installing'
6+
# download directly into ~/bin_compciv
7+
sudo curl http://stedolan.github.io/jq/download/linux64/jq -o /usr/bin/jq
8+
# give it executable permissions
9+
sudo chmod a+x /usr/bin/jq
10+
fi
11+
12+
echo 'Validate connection'
13+
./scripts/boot-validate-connection.sh
14+
15+
echo 'Booting db...'
16+
./scripts/boot-db.sh
17+
18+
echo 'Create the queues...'
19+
./scripts/boot-queues.sh
20+
21+
echo 'Create the lambdas...'
22+
./scripts/boot-lambdas.sh

examples/lambda_api/tests/component/test_lambda_app/events/__init__.py

Whitespace-only changes.

examples/lambda_api/tests/component/test_lambda_app/events/aws/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)