initial impl
This commit is contained in:
parent
98f316da1e
commit
4577370689
@ -9,12 +9,19 @@ RUN cd Cbc-2.9.8 && \
|
||||
./configure && \
|
||||
make && \
|
||||
make install
|
||||
RUN python -m pip install fastapi[all]
|
||||
RUN python -m pip install pySqsListener
|
||||
|
||||
# Bundle app source
|
||||
COPY . /app
|
||||
|
||||
WORKDIR /app/app
|
||||
|
||||
# CMD tail -f /dev/null
|
||||
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "80"]
|
||||
ENV SOLVER_AWS_ACCESS_KEY_ID AKIAWUAUNMG45GJZT2I6
|
||||
ENV SOLVER_AWS_SECRET_ACCESS_KEY voJv2Nc8oyb3mCi6ezn8+oa2tGYN4NwlpLj4YBHR
|
||||
ENV SOLVER_INGEST_BUCKET measure-development-solver-ingest
|
||||
ENV MEASURE_PROCESSED_BUCKET measure-development-solver-processed
|
||||
ENV SOLVER_SQS_INGEST_QUEUE https://sqs.ca-central-1.amazonaws.com/455309353401/measure-development-solver-ingest
|
||||
ENV SOLVER_AWS_REGION ca-central-1
|
||||
|
||||
# CMD [ "python", "main.py" ]
|
||||
CMD tail -f /dev/null
|
||||
|
13
Dockerfile
13
Dockerfile
@ -9,13 +9,18 @@ RUN cd Cbc-2.9.8 && \
|
||||
./configure && \
|
||||
make && \
|
||||
make install
|
||||
RUN python -m pip install fastapi[all]
|
||||
|
||||
RUN python -m pip install pySqsListener
|
||||
|
||||
# Bundle app source
|
||||
COPY . /app
|
||||
|
||||
WORKDIR /app/app
|
||||
|
||||
# CMD tail -f /dev/null
|
||||
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "80"]
|
||||
ENV SOLVER_AWS_ACCESS_KEY_ID AKIAWUAUNMG45GJZT2I6
|
||||
ENV SOLVER_AWS_SECRET_ACCESS_KEY voJv2Nc8oyb3mCi6ezn8+oa2tGYN4NwlpLj4YBHR
|
||||
ENV SOLVER_INGEST_BUCKET measure-development-solver-ingest
|
||||
ENV MEASURE_PROCESSED_BUCKET measure-development-solver-processed
|
||||
ENV SOLVER_SQS_INGEST_QUEUE https://sqs.ca-central-1.amazonaws.com/455309353401/measure-development-solver-ingest
|
||||
ENV SOLVER_AWS_REGION ca-central-1
|
||||
|
||||
CMD [ "python", "main.py" ]
|
||||
|
110
app/main.py
110
app/main.py
@ -1,4 +1,52 @@
|
||||
from fastapi import FastAPI, __version__
|
||||
# from fastapi import FastAPI, __version__
|
||||
|
||||
# app = FastAPI()
|
||||
|
||||
# @app.get("/")
|
||||
# async def root():
|
||||
# return {"message": "Welcome to Measures LOFT solver service. v0.1"}
|
||||
|
||||
# @app.get("/healthcheck")
|
||||
# async def health():
|
||||
# content = {
|
||||
# "maintainer": "Meazure Horizon Team",
|
||||
# "git_repo": "https://github.com/yardstick/measure-solver",
|
||||
# "server": "OK",
|
||||
# "fastapi version": __version__,
|
||||
# "app version": "0.1.0"
|
||||
# }
|
||||
# return content
|
||||
|
||||
# @app.get('/readycheck')
|
||||
# async def ready():
|
||||
# return 'OK!' # just means we're on air
|
||||
|
||||
# @app.post('/solve/')
|
||||
# async def solve(solver_run: SolverRun):
|
||||
# response = Solution(
|
||||
# response_id=randint(100,5000),
|
||||
# forms=[Form(
|
||||
# items=[item.id for item in solver_run.items]
|
||||
# )]
|
||||
# )
|
||||
# return response
|
||||
|
||||
# import os
|
||||
|
||||
# from sqs_listener import SqsListener
|
||||
|
||||
|
||||
# class MyListener(SqsListener):
|
||||
# def handle_message(self, body, attributes, messages_attributes):
|
||||
# print(body)
|
||||
|
||||
# listener = MyListener(os.environ['SOLVER_SQS_INGEST_QUEUE'], error_queue='my-error-queue', region_name='ca-central-1')
|
||||
# listener.listen()
|
||||
import boto3
|
||||
import json
|
||||
import time
|
||||
import os
|
||||
|
||||
from pydantic import BaseModel
|
||||
from typing import Set, List, Optional, Dict
|
||||
from random import randint
|
||||
@ -7,33 +55,39 @@ from models.solver_run import SolverRun
|
||||
from models.solution import Solution
|
||||
from models.form import Form
|
||||
|
||||
app = FastAPI()
|
||||
session = boto3.Session(
|
||||
aws_access_key_id=os.environ['SOLVER_AWS_ACCESS_KEY_ID'],
|
||||
aws_secret_access_key=os.environ['SOLVER_AWS_SECRET_ACCESS_KEY']
|
||||
)
|
||||
|
||||
@app.get("/")
|
||||
async def root():
|
||||
return {"message": "Welcome to Measures LOFT solver service. v0.1"}
|
||||
s3 = session.resource('s3', region_name=os.environ['SOLVER_AWS_REGION'])
|
||||
sqs = session.client('sqs', region_name=os.environ['SOLVER_AWS_REGION'])
|
||||
|
||||
@app.get("/healthcheck")
|
||||
async def health():
|
||||
content = {
|
||||
"maintainer": "Meazure Horizon Team",
|
||||
"git_repo": "https://github.com/yardstick/measure-solver",
|
||||
"server": "OK",
|
||||
"fastapi version": __version__,
|
||||
"app version": "0.1.1"
|
||||
}
|
||||
return content
|
||||
|
||||
@app.get('/readycheck')
|
||||
async def ready():
|
||||
return 'OK' # just means we're on air
|
||||
|
||||
@app.post('/solve/')
|
||||
async def solve(solver_run: SolverRun):
|
||||
response = Solution(
|
||||
response_id=randint(100,5000),
|
||||
forms=[Form(
|
||||
items=[item.id for item in solver_run.items]
|
||||
)]
|
||||
print("STARTING SOLVER APP")
|
||||
# listen to the solver queue
|
||||
while True:
|
||||
msg = sqs.receive_message(
|
||||
QueueUrl=os.environ['SOLVER_SQS_INGEST_QUEUE'],
|
||||
MaxNumberOfMessages=1,
|
||||
WaitTimeSeconds=1
|
||||
)
|
||||
return response
|
||||
|
||||
# get the item from the queue
|
||||
for message in msg.get("Messages", []):
|
||||
print("NEW MESSAGE: ", message)
|
||||
|
||||
# upload the item to the processed bucket
|
||||
# print("INGEST OBJ: ", s3.Object(bucket_name=os.environ['SOLVER_INGEST_BUCKET'],
|
||||
# key=body['Records'][0]['s3']['object']['key']).get()['Body'].read())
|
||||
|
||||
s3.Bucket(os.environ['MEASURE_PROCESSED_BUCKET']).put_object(Key=str(time.time())+'.json', Body=json.dumps({
|
||||
"example": "PROCESSED",
|
||||
"time": time.time(),
|
||||
"parent": message['MessageId']
|
||||
}))
|
||||
|
||||
response = sqs.delete_message(
|
||||
QueueUrl=os.environ['SOLVER_SQS_INGEST_QUEUE'],
|
||||
ReceiptHandle=message['ReceiptHandle'],
|
||||
)
|
||||
print("MESSAGE PROCESSED: ", message['MessageId'])
|
||||
|
@ -1 +1 @@
|
||||
QUANT-987
|
||||
0.2.0
|
||||
|
Loading…
x
Reference in New Issue
Block a user