Skip to content

Commit

Permalink
Replace messy environment var code with library
Browse files Browse the repository at this point in the history
  • Loading branch information
jessemortenson committed Nov 11, 2024
1 parent b1bbef4 commit 892075b
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 10 deletions.
17 changes: 8 additions & 9 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import boto3
import datetime
from environs import Env
import json
import logging
import os
Expand All @@ -22,6 +23,9 @@

stats = Instrumentation()

env = Env()
env.read_env()


def process_import_function(event, context):
"""
Expand Down Expand Up @@ -60,19 +64,14 @@ def process_import_function(event, context):
unique_jurisdictions = {}

# Get the uploaded file's information
sqs_fetch_batch_size = int(os.environ.get("SQS_FETCH_BATCH_SIZE", 600))
sqs_delete_fetched_messages = os.environ.get("SQS_DELETE_FETCHED_MESSAGES", True)
if (
sqs_delete_fetched_messages is not False
and sqs_delete_fetched_messages.lower() != "true" and sqs_delete_fetched_messages != "1"
):
sqs_delete_fetched_messages = True
sqs_fetch_batch_size = env.int("SQS_FETCH_BATCH_SIZE", 600)
sqs_delete_fetched_messages = env.bool("SQS_DELETE_FETCHED_MESSAGES", True)
messages = batch_retrieval_from_sqs(sqs_fetch_batch_size, sqs_delete_fetched_messages)
if not messages:
return

bucket = messages[0].get("bucket")
file_archiving_enabled = os.environ.get("FILE_ARCHIVING_ENABLED")
file_archiving_enabled = env.bool("FILE_ARCHIVING_ENABLED", False)
for message in messages:
bucket = message.get("bucket")
key = message.get("file_path")
Expand Down Expand Up @@ -248,7 +247,7 @@ def retrieve_messages_from_queue(delete_after_fetch=True):
# Create SQS client
sqs = boto3.client("sqs")

sqs_url = os.environ.get("SQS_QUEUE_URL")
sqs_url = env.str("SQS_QUEUE_URL")

# Receive message from SQS queue
response = sqs.receive_message(
Expand Down
55 changes: 54 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ textract = "^1.6.5"
extract-msg = "0.28.7"
black = "^24.4.2"
setuptools = "69.5.1"
environs = "^11.1.0"


[build-system]
Expand Down

0 comments on commit 892075b

Please sign in to comment.