mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-06-08 11:17:27 +00:00
Wire coordination account fallback into config and handler, remove token-refresh retry 🟩
This commit is contained in:
parent
dcff529219
commit
4cd59768c3
2 changed files with 26 additions and 19 deletions
|
|
@ -86,6 +86,8 @@ class Settings(BaseSettings):
|
|||
# Pas Hub
|
||||
PASHUB_EMAIL: Optional[str] = None
|
||||
PASHUB_PASSWORD: Optional[str] = None
|
||||
PASHUB_COORDINATION_EMAIL: Optional[str] = None
|
||||
PASHUB_COORDINATION_PASSWORD: Optional[str] = None
|
||||
|
||||
# Optional AWS creds (only required in local)
|
||||
AWS_ACCESS_KEY_ID: Optional[str] = None
|
||||
|
|
|
|||
|
|
@ -1,9 +1,11 @@
|
|||
from typing import Any, Dict, List
|
||||
from typing import Any, Callable, Dict, List, Optional
|
||||
|
||||
from backend.app.config import get_settings
|
||||
from backend.pashub_fetcher.pashub_client import PashubClient, UnauthorizedError
|
||||
from backend.pashub_fetcher.pashub_client import PashubClient
|
||||
from backend.pashub_fetcher.pashub_service import PashubService
|
||||
from backend.pashub_fetcher.pashub_to_ara_trigger_request import PashubToAraTriggerRequest
|
||||
from backend.pashub_fetcher.pashub_to_ara_trigger_request import (
|
||||
PashubToAraTriggerRequest,
|
||||
)
|
||||
from backend.pashub_fetcher.token_getter import get_token_from_local_storage
|
||||
from backend.app.db.models.tasks import SourceEnum
|
||||
from backend.utils.subtasks import task_handler
|
||||
|
|
@ -28,38 +30,41 @@ def handler(body: Dict[str, Any], context: Any) -> List[str]:
|
|||
|
||||
settings = get_settings()
|
||||
|
||||
pas_hub_email = settings.PASHUB_EMAIL
|
||||
pas_hub_password = settings.PASHUB_PASSWORD
|
||||
pashub_email = settings.PASHUB_EMAIL
|
||||
pashub_password = settings.PASHUB_PASSWORD
|
||||
|
||||
if (not pas_hub_email) or (not pas_hub_password):
|
||||
coordination_hub_email = settings.PASHUB_COORDINATION_EMAIL
|
||||
coordination_hub_password = settings.PASHUB_COORDINATION_PASSWORD
|
||||
coordination_client_factory: Optional[Callable[[], PashubClient]] = None
|
||||
|
||||
if (not pashub_email) or (not pashub_password):
|
||||
raise ValueError("Pas Hub credentials not provided")
|
||||
|
||||
sharepoint_client = DomnaSharepointClient(
|
||||
sharepoint_location=DomnaSites.SOCIAL_HOUSING_WAVE_3
|
||||
)
|
||||
|
||||
if coordination_hub_email and coordination_hub_password:
|
||||
_coord_email, _coord_password = (
|
||||
coordination_hub_email,
|
||||
coordination_hub_password,
|
||||
)
|
||||
coordination_client_factory = lambda: get_pashub_client(
|
||||
_coord_email, _coord_password
|
||||
)
|
||||
|
||||
logger.debug("Validating request body")
|
||||
payload = PashubToAraTriggerRequest.model_validate(body)
|
||||
logger.debug("Successfully validated request body")
|
||||
|
||||
service = PashubService(
|
||||
pashub_client=get_pashub_client(pas_hub_email, pas_hub_password),
|
||||
pashub_client=get_pashub_client(pashub_email, pashub_password),
|
||||
sharepoint_client=sharepoint_client,
|
||||
s3_bucket=S3_BUCKET,
|
||||
coordination_client_factory=coordination_client_factory,
|
||||
)
|
||||
|
||||
try:
|
||||
files: List[str] = service.run(payload)
|
||||
except UnauthorizedError:
|
||||
logger.warning("Token expired - refreshing")
|
||||
|
||||
service = PashubService(
|
||||
pashub_client=get_pashub_client(pas_hub_email, pas_hub_password),
|
||||
sharepoint_client=sharepoint_client,
|
||||
s3_bucket=S3_BUCKET,
|
||||
)
|
||||
|
||||
files = service.run(payload)
|
||||
files: List[str] = service.run(payload)
|
||||
|
||||
logger.info(f"Saved {len(files)} files")
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue