iachat/spec/enterprise/controllers/api/v1/accounts
Muhsin Keloth 20fa5eeaa5
fix: Prevent SLA deletion timeouts by moving to async job (#12944)
This PR fixes the HTTP 500 timeout errors occurring when deleting SLA
policies that have large volumes of historical data.
The fix moves the deletion workflow to asynchronous background
processing using the existing `DeleteObjectJob`.
By offloading heavy cascaded deletions (applied SLAs, SLA events,
conversation nullifications) from the request cycle, the API can now
return immediately while the cleanup continues in the background
avoiding the `Rack::Timeout::RequestTimeoutException`. This ensures that
SLA policies can be deleted reliably, regardless of data size.


### Problem
Deleting an SLA policy via `DELETE
/api/v1/accounts/{account_id}/sla_policies/{id}` fails consistently with
`Rack::Timeout::RequestTimeoutException (15s)` for policies with large
amounts of related data.

Because the current implementation performs all dependent deletions
**synchronously**, Rails processes:

- `has_many :applied_slas, dependent: :destroy` (thousands)
- Each `AppliedSla#destroy` → triggers destruction of many `SlaEvent`
records
- `has_many :conversations, dependent: :nullify` (thousands)

This processing far exceeds the Rack timeout window and consistently
triggers HTTP 500 errors for users.

### Solution

This PR applies the same pattern used successfully in Inbox deletion.

**Move deletion to async background jobs**

- Uses `DeleteObjectJob` for centralized, reliable cleanup.
- Allows the DELETE API call to respond immediately.

**Chunk large datasets**

- Records are processed in **batches of 5,000** to reduce DB load and
avoid job timeouts.
2025-12-10 12:28:47 +05:30
..
agent_capacity_policies fix: Assignment V2 controller fix (#12415) 2025-09-11 19:32:33 +07:00
captain feat: Add UI for custom tools (#12585) 2025-10-06 09:05:54 -07:00
agent_capacity_policies_controller_spec.rb fix: Assignment V2 controller fix (#12415) 2025-09-11 19:32:33 +07:00
agents_controller_spec.rb feat: API changes to support multi step user signup (#8933) 2024-02-20 16:48:51 +05:30
applied_slas_controller_spec.rb fix: Display proper conversation ID with click-to-open in SLA reports (#12570) 2025-10-02 08:18:54 +05:30
audit_logs_controller_spec.rb feat: add auditlogs for account model (#7511) 2023-07-19 23:52:34 +05:30
companies_controller_spec.rb feat: Backend - Companies API endpoint with pagination and search (#12840) 2025-11-18 14:28:56 +05:30
conversations_controller_spec.rb feat: allow querying reporting events via the API (#12832) 2025-11-13 12:46:55 +05:30
custom_roles_controller_spec.rb chore: Fix flaky permissions test (#10074) 2024-09-04 16:13:29 -07:00
reporting_events_controller_spec.rb feat: allow querying reporting events via the API (#12832) 2025-11-13 12:46:55 +05:30
saml_settings_controller_spec.rb feat: add saml model & controller [CW-2958] (#12289) 2025-09-03 13:30:42 -07:00
sla_policies_controller_spec.rb fix: Prevent SLA deletion timeouts by moving to async job (#12944) 2025-12-10 12:28:47 +05:30