mirror of
https://github.com/Sea-Haven-Industries/front-sla-monitor.git
synced 2026-05-18 20:20:14 +00:00
Add inbox filtering and pagination safety limit
Skip the massive Work Orders channel inbox (4,660 conversations) by filtering to named inboxes via MONITOR_INBOXES env var. Add MAX_PAGES=10 pagination cap and cross-inbox dedup. Increase timeout to 300s.
This commit is contained in:
parent
cf23b4a1ce
commit
1aabc6a425
2 changed files with 29 additions and 4 deletions
|
|
@ -74,14 +74,19 @@ def _front_get(url_or_path, params=None):
|
|||
raise RuntimeError(f"Front GET {url_or_path} failed ({e.code}): {body}")
|
||||
|
||||
|
||||
MAX_PAGES = 10
|
||||
|
||||
|
||||
def _front_paginate(path, params=None):
|
||||
results = []
|
||||
data = _front_get(path, params)
|
||||
results.extend(data.get("_results", []))
|
||||
pages = 1
|
||||
|
||||
while data.get("_pagination", {}).get("next"):
|
||||
while data.get("_pagination", {}).get("next") and pages < MAX_PAGES:
|
||||
data = _front_get(data["_pagination"]["next"])
|
||||
results.extend(data.get("_results", []))
|
||||
pages += 1
|
||||
|
||||
return results
|
||||
|
||||
|
|
@ -260,12 +265,24 @@ def handler(event, context):
|
|||
|
||||
now = datetime.now(timezone.utc)
|
||||
|
||||
monitor_names = os.environ.get("MONITOR_INBOXES", "").strip()
|
||||
if monitor_names:
|
||||
monitor_set = {n.strip().lower() for n in monitor_names.split(",")}
|
||||
else:
|
||||
monitor_set = None
|
||||
|
||||
inboxes = _front_paginate("/inboxes")
|
||||
shared = [i for i in inboxes if not i.get("is_private", False)]
|
||||
logger.info("Found %d shared inboxes", len(shared))
|
||||
|
||||
if monitor_set:
|
||||
shared = [i for i in shared if i.get("name", "").lower() in monitor_set]
|
||||
|
||||
logger.info("Monitoring %d inboxes: %s", len(shared),
|
||||
", ".join(i.get("name", "?") for i in shared))
|
||||
|
||||
tier1_count = 0
|
||||
tier2_count = 0
|
||||
seen = set()
|
||||
|
||||
for inbox in shared:
|
||||
inbox_id = inbox["id"]
|
||||
|
|
@ -280,9 +297,12 @@ def handler(event, context):
|
|||
logger.error("Failed to fetch conversations for %s: %s", inbox_name, e)
|
||||
continue
|
||||
|
||||
logger.info("Inbox '%s': %d open conversations", inbox_name, len(conversations))
|
||||
logger.info("Inbox '%s': %d recent open conversations", inbox_name, len(conversations))
|
||||
|
||||
for conv in conversations:
|
||||
if conv.get("id") in seen:
|
||||
continue
|
||||
seen.add(conv.get("id"))
|
||||
try:
|
||||
last_msg = conv.get("last_message")
|
||||
if not last_msg or last_msg.get("type") != "inbound":
|
||||
|
|
|
|||
|
|
@ -24,11 +24,15 @@ Parameters:
|
|||
Type: Number
|
||||
Default: 1440
|
||||
Description: Business minutes before Tier 2 alert (1 business day)
|
||||
MonitorInboxes:
|
||||
Type: String
|
||||
Default: "Triage,California,West Coast,Central,East Coast,Vendors"
|
||||
Description: Comma-separated inbox names to monitor (empty = all shared)
|
||||
|
||||
Globals:
|
||||
Function:
|
||||
Runtime: python3.12
|
||||
Timeout: 120
|
||||
Timeout: 300
|
||||
MemorySize: 128
|
||||
Architectures:
|
||||
- arm64
|
||||
|
|
@ -71,6 +75,7 @@ Resources:
|
|||
TABLE_NAME: !Ref AlertsTable
|
||||
ACK_SLA_MINUTES: !Ref AckSlaMinutes
|
||||
ACTION_SLA_MINUTES: !Ref ActionSlaMinutes
|
||||
MONITOR_INBOXES: !Ref MonitorInboxes
|
||||
Policies:
|
||||
- DynamoDBCrudPolicy:
|
||||
TableName: !Ref AlertsTable
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue