irt-service/app/main.py

58 lines
1.8 KiB
Python

import os, sys, logging
from lib.application_configs import ApplicationConfigs
from services.loft_service import LoftService
from helpers import aws_helper
from daemonize import Daemonize
from sqspy import Consumer
logging.basicConfig(stream=sys.stdout,
level=logging.INFO,
format="%(levelname)s %(asctime)s - %(message)s")
class ServiceListener(Consumer):
def handle_message(self, body, attributes, messages_attributes):
# gather/manage/process data based on the particular needs
logging.info('Incoming message: %s', body)
service = LoftService(body)
service.process()
logging.info('Process complete for %s', service.file_name)
def main():
logging.info('Starting Solver Service: That Was Rash (v1.4.0)...')
# ToDo: Figure out a much better way of doing this.
# LocalStack wants 'endpoint_url', while prod doesnt :(
if ApplicationConfigs.local_dev_env:
listener = ServiceListener(
None,
ApplicationConfigs.sqs_queue,
create_queue=False,
region_name=ApplicationConfigs.region_name,
aws_access_key=ApplicationConfigs.aws_access_key_id,
aws_secret_key=ApplicationConfigs.aws_secret_key,
endpoint_url=ApplicationConfigs.endpoint_url)
else:
listener = ServiceListener(
None,
ApplicationConfigs.sqs_queue,
create_queue=False,
region_name=ApplicationConfigs.region_name,
aws_access_key=ApplicationConfigs.aws_access_key_id,
aws_secret_key=ApplicationConfigs.aws_secret_key)
listener.listen()
if __name__ == '__main__':
myname = os.path.basename(sys.argv[0])
pidfile = '/tmp/%s' % myname
daemon = Daemonize(app=myname, pid=pidfile, action=main, foreground=True)
daemon.start()