Unhappy with push_listener

This commit is contained in:
Jonas Linter
2025-10-06 11:09:08 +02:00
parent 68e49aab34
commit 87668e6dc0

View File

@@ -71,26 +71,31 @@ event_dispatcher = EventDispatcher()
# Load config at startup
async def push_listener(customer, reservation, hotel, push):
async def push_listener(customer: DBCustomer, reservation: DBReservation, hotel):
push_endpoint = hotel.get("push_endpoint")
server: AlpineBitsServer = app.state.alpine_bits_server
hotel_id = hotel['hotel_id']
reservation_hotel_id = reservation.hotel_code
action = "OTA_HotelResNotifRQ"
# request = server.handle_request(
# action,)
headers = {"Authorization": f"Bearer {push.get('token','')}"} if push.get('token') else {}
headers = {"Authorization": f"Bearer {push_endpoint.get('token','')}"} if push_endpoint.get('token') else {}
try:
async with httpx.AsyncClient() as client:
resp = await client.post(push["url"], json=payload, headers=headers, timeout=10)
_LOGGER.info(f"Push event fired to {push['url']} for hotel {hotel['hotel_id']}, status: {resp.status_code}")
resp = await client.post(push_endpoint["url"], json=payload, headers=headers, timeout=10)
_LOGGER.info(f"Push event fired to {push_endpoint['url']} for hotel {hotel['hotel_id']}, status: {resp.status_code}")
except Exception as e:
_LOGGER.error(f"Push event failed for hotel {hotel['hotel_id']}: {e}")
@@ -114,12 +119,13 @@ async def lifespan(app: FastAPI):
app.state.alpine_bits_server = AlpineBitsServer(config)
app.state.event_dispatcher = event_dispatcher
# Register push listeners for hotels with push_endpoint
for hotel in config.get("alpine_bits_auth", []):
push = hotel.get("push_endpoint")
if push:
push_endpoint = hotel.get("push_endpoint")
if push_endpoint:
event_dispatcher.register("form_processed", partial(push_listener, hotel=hotel, push=push))
event_dispatcher.register("form_processed", partial(push_listener, hotel=hotel))
# Create tables
async with engine.begin() as conn: