make more functional v2

This commit is contained in:
brmnjsh 2023-09-06 15:37:42 +00:00
parent 55a0f7c254
commit dfeb65c900

View File

@ -14,6 +14,11 @@ logging.basicConfig(stream=sys.stdout,
class ServiceListener(Consumer):
# add new services here
SERVICES = {
FormGenerationService.ACTION: FormGenerationService,
AbilityEstimationService.ACTION: AbilityEstimationService
}
def handle_message(self, body, attributes, messages_attributes):
# gather/manage/process data based on the particular needs
@ -23,25 +28,20 @@ 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 = None
# 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)
if action in self.SERVICES:
service = self.SERVICES[action](body)
service.process()
logging.info('Process complete for %s', service.file_name)
else:
logging.error(f'action of type {action} does not exist.')
return
service.process()
logging.info('Process complete for %s', service.file_name)
def main():
logging.info('Starting IRT Service: That Was Rash (v1.4.0)...')