diff --git a/applications/audit_generator/local_handler/docker-compose.yml b/applications/audit_generator/local_handler/docker-compose.yml new file mode 100644 index 000000000..cc3f89fc9 --- /dev/null +++ b/applications/audit_generator/local_handler/docker-compose.yml @@ -0,0 +1,11 @@ +version: "3.9" + +services: + audit-generator-lambda: + build: + context: ../../../ + dockerfile: applications/audit_generator/handler/Dockerfile + ports: + - "9001:8080" + env_file: + - ../../../.env diff --git a/applications/audit_generator/local_handler/invoke_local_lambda.py b/applications/audit_generator/local_handler/invoke_local_lambda.py new file mode 100644 index 000000000..14d1339a3 --- /dev/null +++ b/applications/audit_generator/local_handler/invoke_local_lambda.py @@ -0,0 +1,29 @@ +#!/usr/bin/env python3 +import json +import requests + +HOST = "localhost" +PORT = "9001" + +LAMBDA_URL = f"http://{HOST}:{PORT}/2015-03-31/functions/function/invocations" + +payload = { + "Records": [ + { + "messageId": "test-message-id", + "body": json.dumps( + { + "task_id": "00000000-0000-0000-0000-000000000001", + "sub_task_id": "00000000-0000-0000-0000-000000000002", + "hubspot_deal_id": "500311510234", + } + ), + } + ] +} + +response = requests.post(LAMBDA_URL, json=payload) + +print("Status code:", response.status_code) +print("Response:") +print(response.text) diff --git a/applications/audit_generator/local_handler/invoke_local_orchestrator.py b/applications/audit_generator/local_handler/invoke_local_orchestrator.py new file mode 100644 index 000000000..edc7bb8f4 --- /dev/null +++ b/applications/audit_generator/local_handler/invoke_local_orchestrator.py @@ -0,0 +1,57 @@ +#!/usr/bin/env python3 +"""Run AuditGeneratorOrchestrator directly, bypassing @subtask_handler. + +Loads credentials from the repo-root .env file so no DB task/subtask rows +are needed. +""" + +import os +import sys +from pathlib import Path +from typing import Any + +import boto3 +from dotenv import load_dotenv + +REPO_ROOT = Path(__file__).resolve().parents[3] +load_dotenv(REPO_ROOT / ".env") + +sys.path.insert(0, str(REPO_ROOT)) + +from utilities.logger import setup_logger + +setup_logger() + +from infrastructure.postgres.config import PostgresConfig +from infrastructure.postgres.engine import make_engine, make_session +from infrastructure.s3.s3_client import S3Client +from orchestration.audit_generator_orchestrator import AuditGeneratorOrchestrator +from orchestration.audit_generator_unit_of_work import AuditGeneratorUnitOfWork + +HUBSPOT_DEAL_ID = "505712829658" + +boto3_client: Any = boto3.client # type: ignore[attr-defined] +s3_client = S3Client( + boto_s3_client=boto3_client("s3"), + # bucket=os.environ["S3_BUCKET_NAME"], + bucket="retrofit-energy-assessments-dev", +) + +engine = make_engine(PostgresConfig.from_env(os.environ)) + + +def session_factory() -> Any: + return make_session(engine) + + +def uow_factory() -> AuditGeneratorUnitOfWork: + return AuditGeneratorUnitOfWork(session_factory) + + +print(f"Running AuditGeneratorOrchestrator for deal: {HUBSPOT_DEAL_ID!r}") +AuditGeneratorOrchestrator( + hubspot_deal_id=HUBSPOT_DEAL_ID, + s3_client=s3_client, + uow_factory=uow_factory, +).run() +print("Done")