mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-06-08 11:17:27 +00:00
made lambda async and 15 min timeout
This commit is contained in:
parent
e99f1506f9
commit
9453ffb401
4 changed files with 32 additions and 9 deletions
|
|
@ -1719,7 +1719,7 @@ class AssetList:
|
|||
solar_reason_map = {
|
||||
"solar_eligible": "Solar Eligible: ",
|
||||
"solar_eligible_needs_heating_upgrade": (
|
||||
"Solar Eligible, Solid Floor, Needs Heating Upgrade: "
|
||||
"Solar Eligible, Needs Heating Upgrade: "
|
||||
),
|
||||
"solar_eligible_solid_wall_uninsulated": "Solar Eligible, Solid Wall Uninsulated, EPC E or Below: ",
|
||||
}
|
||||
|
|
@ -2140,10 +2140,8 @@ class AssetList:
|
|||
return
|
||||
|
||||
# TODO: Fetch from Sharepoint
|
||||
ecosurv_filepath = "/Users/khalimconn-kowlessar/Documents/hestia/Ecosurv/07.csv"
|
||||
logger.info(
|
||||
"Getting Ecosurv data from %s", ecosurv_filepath
|
||||
)
|
||||
ecosurv_filepath = "/Users/khalimconn-kowlessar/Documents/hestia/Ecosurv/15.04.csv"
|
||||
logger.info("Getting Ecosurv data from %s", ecosurv_filepath)
|
||||
self.ecosurv = pd.read_csv(
|
||||
ecosurv_filepath,
|
||||
encoding="cp437"
|
||||
|
|
@ -2214,6 +2212,9 @@ class AssetList:
|
|||
unmatched.append(row["Reference"])
|
||||
continue
|
||||
|
||||
logger.info("Matched %s properties to ecosurv data", len(matched))
|
||||
logger.info("%s properties in Ecosurv remain unmatched", len(unmatched))
|
||||
|
||||
# We now match
|
||||
matched = pd.DataFrame(matched)
|
||||
self.standardised_asset_list = self.standardised_asset_list.merge(
|
||||
|
|
|
|||
|
|
@ -124,7 +124,7 @@ def app():
|
|||
]
|
||||
master_to_asset_list_filepath = None
|
||||
phase = False
|
||||
ecosuv_landlords = "paul butler|bromford"
|
||||
ecosurv_landlords = "paul butler|bromford"
|
||||
|
||||
# Torus
|
||||
data_folder = "/Users/khalimconn-kowlessar/Documents/hestia/Customers/Torus/Phase 1"
|
||||
|
|
@ -609,6 +609,8 @@ def app():
|
|||
master_to_asset_list_filepath=master_to_asset_list_filepath
|
||||
)
|
||||
|
||||
asset_list.flag_ecosurv(ecosurv_landlords)
|
||||
|
||||
### We retrieve the EPC data
|
||||
|
||||
# We chunk up this data into 5000 rows at a time
|
||||
|
|
@ -950,5 +952,8 @@ def app():
|
|||
if not asset_list.outcomes_no_match.empty:
|
||||
asset_list.outcomes_no_match.to_excel(writer, sheet_name="Unmatched Outcomes", index=False)
|
||||
|
||||
if not asset_list.ecosurv_no_match.empty:
|
||||
asset_list.ecosurv_no_match.to_excel(writer, sheet_name="Unmatched Ecosurv", index=False)
|
||||
|
||||
# Store the Hubspot export as a csv
|
||||
hubspot_data.to_csv(os.path.join(data_folder, "Hubspot Export.csv"), index=False)
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import ast
|
||||
import asyncio
|
||||
import json
|
||||
from datetime import datetime
|
||||
|
||||
|
|
@ -420,9 +421,23 @@ router = APIRouter(
|
|||
)
|
||||
|
||||
|
||||
@router.post("/trigger")
|
||||
async def trigger_plan(body: PlanTriggerRequest):
|
||||
@router.post("/trigger", status_code=202)
|
||||
async def trigger_plan_entrypoint(body: PlanTriggerRequest):
|
||||
"""
|
||||
This function is the entrypoint for the plan trigger API. It will handle the request and call the
|
||||
trigger_plan function.
|
||||
:param body: The request body
|
||||
:return:
|
||||
"""
|
||||
logger.info("API triggered with body: %s", body)
|
||||
# Kick off the async background task
|
||||
asyncio.create_task(model_engine(body))
|
||||
|
||||
return {"message": "Plan job accepted"}
|
||||
|
||||
|
||||
async def model_engine(body: PlanTriggerRequest):
|
||||
logger.info("Model Engine triggered with body: %s", body)
|
||||
|
||||
logger.info("Connecting to db")
|
||||
session = sessionmaker(bind=db_engine)()
|
||||
|
|
@ -1056,4 +1071,6 @@ async def trigger_plan(body: PlanTriggerRequest):
|
|||
finally:
|
||||
session.close()
|
||||
|
||||
logger.info("Model Engine completed successfully")
|
||||
|
||||
return Response(status_code=200)
|
||||
|
|
|
|||
|
|
@ -81,4 +81,4 @@ functions:
|
|||
- http:
|
||||
path: /{proxy+}
|
||||
method: ANY
|
||||
timeout: 120
|
||||
timeout: 900 # Max timeout to 15 mins for engine runs
|
||||
Loading…
Add table
Reference in a new issue