Skip to content

Commit

Permalink
feat: Use API through environment variable
Browse files Browse the repository at this point in the history
  • Loading branch information
cballevre committed Mar 3, 2024
1 parent aa43f0c commit ca536cb
Show file tree
Hide file tree
Showing 6 changed files with 5 additions and 11 deletions.
3 changes: 1 addition & 2 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
DATABASE_URL=mongodb+srv://username:[email protected]/?retryWrites=true&w=majority
DATABASE_NAME=Astrolabe
API_URL="http://localhost:3000/api/v1"

S3_ENDPOINT="https://s3.fr-par.scw.cloud"
S3_BUCKET='astrolabe-expeditions-data'
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,8 @@ jobs:
SCW_PROJECT: ${{ secrets.SCW_PROJECT }}
SCW_TOKEN: ${{ secrets.SCW_TOKEN }}
SCW_REGISTRY: ${{ secrets.SCW_REGISTRY }}
DATABASE_URL: ${{ secrets.DATABASE_URL }}
DATABASE_NAME: ${{ secrets.DATABASE_NAME }}
S3_ENDPOINT: ${{ secrets.S3_ENDPOINT }}
S3_BUCKET: ${{ secrets.S3_BUCKET }}
S3_ID: ${{ secrets.S3_ID }}
S3_SECRET: ${{ secrets.S3_SECRET }}
API_URL: ${{ secrets.API_URL }}
3 changes: 1 addition & 2 deletions serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ custom:
port: 8080
timeout: 10s
secret:
DATABASE_URL: ${env:DATABASE_URL}
DATABASE_NAME: ${env:DATABASE_NAME}
API_URL: ${env:API_URL}
S3_ENDPOINT: ${env:S3_ENDPOINT}
S3_BUCKET: ${env:S3_BUCKET}
S3_ID: ${env:S3_ID}
Expand Down
4 changes: 2 additions & 2 deletions src/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def process_file(file_id):
load_dotenv() # load environment variables from .env file

# Retrieve the file JSON via the API route
file_url = f"http://localhost:3000/api/v1/files/{file_id}"
file_url = os.environ['API_URL'] + f"/files/{file_id}"
response = requests.get(file_url)
if response.status_code == 200:
file = response.json()['data']
Expand Down Expand Up @@ -86,7 +86,7 @@ def process_file(file_id):
batch_data.append(transformed_data)
batch_data_json = json.dumps(batch_data, cls=PandasEncoder)

response = requests.post(f"http://localhost:3000/api/v1/sensors/{file['sensor_id']}/records/create_or_update_many", json={
response = requests.post( os.environ['API_URL'] + f"/sensors/{file['sensor_id']}/records/create_or_update_many", json={
"data": batch_data_json
})

Expand Down
2 changes: 0 additions & 2 deletions src/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ def resource_not_found(e):

@app.route("/", methods=HTTP_METHODS)
def root():
print(request.get_data(), flush=True)
data = json.loads(request.get_data())
print(f"Processing file n°{data['file_id']}")
result = process_file(data['file_id'])
return result

Expand Down
1 change: 0 additions & 1 deletion src/sqs.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,5 @@

for message in messages:
content = json.loads(message.body)
print(f"Processing file n°{content['file_id']}")
result = process_file(content['file_id'])
message.delete()

0 comments on commit ca536cb

Please sign in to comment.