diff --git a/apps/api/src/core/config.py b/apps/api/src/core/config.py index 1be2d5f3..1b47c9f3 100644 --- a/apps/api/src/core/config.py +++ b/apps/api/src/core/config.py @@ -705,12 +705,12 @@ class Settings(BaseSettings): ), ) AWOOOP_ANSIBLE_CANDIDATE_BACKFILL_INTERVAL_SECONDS: int = Field( - default=300, + default=600, ge=60, description="Polling interval for the Ansible candidate backfill worker.", ) AWOOOP_ANSIBLE_CANDIDATE_BACKFILL_BATCH_LIMIT: int = Field( - default=5, + default=2, ge=1, le=25, description="Maximum backfilled incidents queued per worker tick.", diff --git a/apps/api/src/jobs/awooop_ansible_candidate_backfill_job.py b/apps/api/src/jobs/awooop_ansible_candidate_backfill_job.py index 2858239f..7307b8fe 100644 --- a/apps/api/src/jobs/awooop_ansible_candidate_backfill_job.py +++ b/apps/api/src/jobs/awooop_ansible_candidate_backfill_job.py @@ -43,6 +43,7 @@ async def _fetch_missing_candidate_incidents( scan_limit: int, ) -> list[dict[str, Any]]: async with get_db_context(project_id) as db: + await db.execute(text("SET LOCAL statement_timeout = '5000ms'")) result = await db.execute( text(""" SELECT @@ -69,6 +70,7 @@ async def _fetch_missing_candidate_incidents( SELECT 1 FROM automation_operation_log existing WHERE existing.operation_type = 'ansible_candidate_matched' + AND existing.created_at >= NOW() - (:window_hours * INTERVAL '1 hour') AND existing.input ->> 'executor' = 'ansible' AND coalesce(existing.incident_id::text, existing.input ->> 'incident_id') = incidents.incident_id::text ) diff --git a/apps/api/src/services/awooop_ansible_check_mode_service.py b/apps/api/src/services/awooop_ansible_check_mode_service.py index d8c1a990..7bbab388 100644 --- a/apps/api/src/services/awooop_ansible_check_mode_service.py +++ b/apps/api/src/services/awooop_ansible_check_mode_service.py @@ -648,6 +648,7 @@ async def backfill_missing_auto_repair_execution_receipts_once( stats = {"scanned": 0, "written": 0, "skipped": 0, "error": None} try: async with get_db_context(project_id) as db: + await db.execute(text("SET LOCAL statement_timeout = '5000ms'")) result = await db.execute( text(""" SELECT @@ -667,7 +668,9 @@ async def backfill_missing_auto_repair_execution_receipts_once( AND NOT EXISTS ( SELECT 1 FROM auto_repair_executions existing - WHERE existing.executed_steps::text LIKE '%' || apply.op_id::text || '%' + WHERE existing.created_at >= NOW() - (:window_hours * INTERVAL '1 hour') + AND existing.triggered_by = 'ansible_controlled_apply' + AND existing.executed_steps::text LIKE '%' || apply.op_id::text || '%' ) ORDER BY apply.created_at DESC LIMIT :limit diff --git a/k8s/awoooi-prod/06-deployment-api.yaml b/k8s/awoooi-prod/06-deployment-api.yaml index f90d722f..1cf2437a 100644 --- a/k8s/awoooi-prod/06-deployment-api.yaml +++ b/k8s/awoooi-prod/06-deployment-api.yaml @@ -140,9 +140,9 @@ spec: - name: ENABLE_AWOOOP_ANSIBLE_CANDIDATE_BACKFILL_WORKER value: "true" - name: AWOOOP_ANSIBLE_CANDIDATE_BACKFILL_INTERVAL_SECONDS - value: "300" + value: "600" - name: AWOOOP_ANSIBLE_CANDIDATE_BACKFILL_BATCH_LIMIT - value: "5" + value: "2" - name: AWOOOP_ANSIBLE_CANDIDATE_BACKFILL_WINDOW_HOURS value: "24" - name: AWOOOP_ANSIBLE_CANDIDATE_BACKFILL_STARTUP_SLEEP_SECONDS