add more typing, add tag to file upload, and rename form generation service
This commit is contained in:
parent
386ab25515
commit
d90f51faca
@ -1,5 +1,5 @@
|
|||||||
import boto3
|
import boto3
|
||||||
import json
|
import io
|
||||||
|
|
||||||
from lib.application_configs import ApplicationConfigs
|
from lib.application_configs import ApplicationConfigs
|
||||||
|
|
||||||
@ -16,21 +16,21 @@ else:
|
|||||||
s3 = session.client('s3', region_name=ApplicationConfigs.region_name)
|
s3 = session.client('s3', region_name=ApplicationConfigs.region_name)
|
||||||
sqs = session.client('sqs', region_name=ApplicationConfigs.region_name)
|
sqs = session.client('sqs', region_name=ApplicationConfigs.region_name)
|
||||||
|
|
||||||
def get_key_from_message(body):
|
def get_key_from_message(body: dict):
|
||||||
return body['Records'][0]['s3']['object']['key']
|
return body['Records'][0]['s3']['object']['key']
|
||||||
|
|
||||||
|
|
||||||
def get_bucket_from_message(body):
|
def get_bucket_from_message(body: dict):
|
||||||
return body['Records'][0]['s3']['bucket']['name']
|
return body['Records'][0]['s3']['bucket']['name']
|
||||||
|
|
||||||
|
|
||||||
def get_object(key, bucket):
|
def get_object(key: str, bucket: str):
|
||||||
return s3.get_object(
|
return s3.get_object(
|
||||||
Bucket=bucket,
|
Bucket=bucket,
|
||||||
Key=key,
|
Key=key,
|
||||||
)['Body'].read()
|
)['Body'].read()
|
||||||
|
|
||||||
def get_object_tag(key, bucket, tag_key):
|
def get_object_tag(key: str, bucket: str, tag_key: str):
|
||||||
tags = get_object_tags(key, bucket)
|
tags = get_object_tags(key, bucket)
|
||||||
tag_index = 0
|
tag_index = 0
|
||||||
|
|
||||||
@ -41,20 +41,10 @@ def get_object_tag(key, bucket, tag_key):
|
|||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def get_object_tags(key, bucket):
|
def get_object_tags(key: str, bucket: str):
|
||||||
tags = s3.get_object_tagging(Bucket=bucket, Key=key)['TagSet']
|
tags = s3.get_object_tagging(Bucket=bucket, Key=key)['TagSet']
|
||||||
return tags
|
return tags
|
||||||
|
|
||||||
|
|
||||||
def file_stream_upload(buffer, name, bucket):
|
def file_stream_upload(buffer: io.BytesIO, name: str, bucket: str, action: str = None):
|
||||||
return s3.upload_fileobj(buffer, bucket, name)
|
return s3.upload_fileobj(buffer, bucket, name, ExtraArgs={'Tagging': f'action={action}'})
|
||||||
|
|
||||||
|
|
||||||
def receive_message(queue, message_num=1, wait_time=1):
|
|
||||||
return sqs.receive_message(QueueUrl=queue,
|
|
||||||
MaxNumberOfMessages=message_num,
|
|
||||||
WaitTimeSeconds=wait_time)
|
|
||||||
|
|
||||||
|
|
||||||
def delete_message(queue, receipt):
|
|
||||||
return sqs.delete_message(QueueUrl=queue, ReceiptHandle=receipt)
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import os, sys, logging
|
import os, sys, logging
|
||||||
|
|
||||||
from lib.application_configs import ApplicationConfigs
|
from lib.application_configs import ApplicationConfigs
|
||||||
from services.loft_service import LoftService
|
from services.form_generation_service import FormGenerationService
|
||||||
from helpers import aws_helper
|
from helpers import aws_helper
|
||||||
|
|
||||||
from daemonize import Daemonize
|
from daemonize import Daemonize
|
||||||
@ -18,14 +18,14 @@ class ServiceListener(Consumer):
|
|||||||
# gather/manage/process data based on the particular needs
|
# gather/manage/process data based on the particular needs
|
||||||
logging.info('Incoming message: %s', body)
|
logging.info('Incoming message: %s', body)
|
||||||
|
|
||||||
service = LoftService(body)
|
service = FormGenerationService(body)
|
||||||
service.process()
|
service.process()
|
||||||
|
|
||||||
logging.info('Process complete for %s', service.file_name)
|
logging.info('Process complete for %s', service.file_name)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
logging.info('Starting Solver Service: That Was Rash (v1.4.0)...')
|
logging.info('Starting IRT Service: That Was Rash (v1.4.0)...')
|
||||||
|
|
||||||
# ToDo: Figure out a much better way of doing this.
|
# ToDo: Figure out a much better way of doing this.
|
||||||
# LocalStack wants 'endpoint_url', while prod doesnt :(
|
# LocalStack wants 'endpoint_url', while prod doesnt :(
|
||||||
|
@ -15,7 +15,7 @@ from models.target import Target
|
|||||||
from services.base import Base
|
from services.base import Base
|
||||||
|
|
||||||
|
|
||||||
class LoftService(Base):
|
class FormGenerationService(Base):
|
||||||
|
|
||||||
def process(self):
|
def process(self):
|
||||||
try:
|
try:
|
||||||
@ -256,4 +256,4 @@ class LoftService(Base):
|
|||||||
# upload generated file to s3 and return result
|
# upload generated file to s3 and return result
|
||||||
return aws_helper.file_stream_upload(
|
return aws_helper.file_stream_upload(
|
||||||
solution_file, self.file_name,
|
solution_file, self.file_name,
|
||||||
ApplicationConfigs.s3_processed_bucket)
|
ApplicationConfigs.s3_processed_bucket, 'formGeneration')
|
Loading…
x
Reference in New Issue
Block a user