diff --git a/app/helpers/aws_helper.py b/app/helpers/aws_helper.py index c8c31b4..cfcf7f6 100644 --- a/app/helpers/aws_helper.py +++ b/app/helpers/aws_helper.py @@ -20,11 +20,9 @@ else: def get_key_from_message(body: dict) -> str: return body['Records'][0]['s3']['object']['key'] - def get_bucket_from_message(body: dict) -> str: return body['Records'][0]['s3']['bucket']['name'] - def get_object(key: str, bucket: str) -> bytes: return s3.get_object( Bucket=bucket, diff --git a/app/main.py b/app/main.py index 617d886..3374c2f 100644 --- a/app/main.py +++ b/app/main.py @@ -23,7 +23,21 @@ class ServiceListener(Consumer): # but depending on if we can add the tagset to the sqs message body # we either extract that and then delegate to the appropriate service # or get the action tag from the object through the aws helper function - service = FormGenerationService(body) + service = None + key = aws_helper.get_key_from_message(body) + bucket = aws_helper.get_bucket_from_message(body) + action = aws_helper.get_object_tag(key, bucket, 'action')['Value'] + + logging.info(f'Process starting for {action}') + + if action == 'formGeneration': + service = FormGenerationService(body) + elif action == 'abilityEstimation': + service = AbilityEstimationService(body) + else: + logging.error(f'action of type {action} does not exist.') + return + service.process() logging.info('Process complete for %s', service.file_name) diff --git a/app/services/ability_estimation_service.py b/app/services/ability_estimation_service.py index 5dafdac..daaa308 100644 --- a/app/services/ability_estimation_service.py +++ b/app/services/ability_estimation_service.py @@ -1,4 +1,8 @@ +import logging + from services.base import Base class AbilityEstimationService(Base): - pass + + def process(self): + logging.info('Ability Estimation Service to be implemented...') diff --git a/app/services/form_generation_service.py b/app/services/form_generation_service.py index f62d6e5..95ce8e8 100644 --- a/app/services/form_generation_service.py +++ b/app/services/form_generation_service.py @@ -1,4 +1,4 @@ -import os, json, random, io, logging +import json, random, io, logging from pulp import LpProblem, LpVariable, LpMinimize, LpMaximize, LpAffineExpression, LpConstraint, LpStatus, lpSum @@ -9,7 +9,6 @@ from lib.errors.item_generation_error import ItemGenerationError from models.solver_run import SolverRun from models.solution import Solution from models.form import Form -from models.item import Item from models.target import Target from services.base import Base