Skip to content

Commit

Permalink
Cleaned up code
Browse files Browse the repository at this point in the history
Removed unneeded files
refactored code from ingest service into blaise service
got some basic tests running (needs more work)
  • Loading branch information
lambeb committed Jan 24, 2025
1 parent 11cc3d5 commit fc58c6e
Show file tree
Hide file tree
Showing 20 changed files with 154 additions and 1,124 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,8 @@ To give you the path to python for your virtual env run:
```
echo "$(poetry env info | grep Path | awk '{print $2}')/bin/python"
```

Run unit tests:
```shell
poetry run python -m pytest
```
11 changes: 2 additions & 9 deletions appconfig/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,14 @@
class Config:
blaise_api_url: str
blaise_server_park: str
project_id: str
topic_name: str
env: str

@classmethod
def from_env(cls):
return cls(
blaise_api_url=os.getenv("BLAISE_API_URL"),
blaise_server_park=os.getenv("BLAISE_SERVER_PARK"),
project_id=os.getenv("PROJECT_ID"),
topic_name=os.getenv("TOPIC_NAME"),
env=os.getenv("ENV"),
)

def log(self):
print(f"Configuration: Project ID: {self.project_id}")
print(f"Configuration: Topic Name: {self.topic_name}")
print(f"Configuration: Env: {self.env}")
print(f"Configuration: Blaise API Url: {self.blaise_api_url}")
print(f"Configuration: Blaise Server Park: {self.blaise_server_park}")
172 changes: 0 additions & 172 deletions appconfig/message.py

This file was deleted.

19 changes: 11 additions & 8 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import logging

import utils
from services.ingest_service import IngestService
from services.validation_service import ValidationService
from appconfig.config import Config
from services.blaise_service import BlaiseService
Expand All @@ -10,7 +9,6 @@
BlaiseError,
ConfigError,
GuidError,
QuestionnaireNotFound,
RequestError,
UsersError,
IngestError,
Expand All @@ -20,7 +18,7 @@
setup_logger()


def process_zip_file(data, context):
def process_zip_file(data):
try:
logging.info("Running Cloud Function - 'ingest data'")
validation_service = ValidationService()
Expand All @@ -34,7 +32,7 @@ def process_zip_file(data, context):
print(f"File {file_name} is not a zip file, skipping.")
return

print(f"Processing ZIP file: {file_name}")
print(f"Processing ZIP file: {file_name} from bucket {bucket_name}")

# Initialize the client
storage_client = storage.Client()
Expand All @@ -56,17 +54,19 @@ def process_zip_file(data, context):

questionnaire_name = utils.get_questionnaire_name(file_name)

# Blaise Handler TODO: Get questionnaire_name from somewhere and validate it exists
# Blaise Handler
validation_service.validate_questionnaire_exists(
questionnaire_name, blaise_config
)

# Ingest Handler
blaise_service = BlaiseService(blaise_config)
ingest_service = IngestService(blaise_service)

logging.info(f"Calling Ingest Service with server park: {blaise_server_park} and questionnaire name: {questionnaire_name}")
ingest_service.ingest(blaise_server_park, questionnaire_name)
logging.info(f"Calling Ingest Service with "
f"server park: {blaise_server_park}, "
f"questionnaire name: {questionnaire_name}, "
f"file name: {file_name}")
blaise_service.get_ingest(blaise_server_park, questionnaire_name, file_name)
logging.info("Finished Running Cloud Function - 'ingest data'")

return f"Successfully ingested file from bucket", 200
Expand All @@ -83,3 +83,6 @@ def process_zip_file(data, context):
error_message = f"Error occurred during Ingest: {e}"
logging.error(error_message)
return error_message, 500

# Testing
process_zip_file()
7 changes: 7 additions & 0 deletions mypi.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[mypy]
disallow_untyped_defs = False
namespace_packages = True
exclude = "scripts/"

[mypy-blaise_restapi.*]
ignore_missing_imports = True
Loading

0 comments on commit fc58c6e

Please sign in to comment.