iachat/app/jobs
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
..
account feat: Introduce the crm_v2 feature flag for CRM changes (#12014) 2025-07-23 17:07:02 +04:00
agent_bots feat: Open conversation when agent bot webhook fails (#12379) 2025-10-13 15:59:59 +05:30
agents chore: Reorganize Sidekiq Queues (#6976) 2023-05-04 15:44:16 +05:30
auto_assignment feat: Assignment service (v2) (#12320) 2025-11-17 10:08:25 +05:30
avatar fix: Add URL validation and rate limiting for contact avatar sync (#11979) 2025-09-10 20:08:06 +05:30
campaigns chore: one off SMS campaign APIs (#2589) 2021-07-14 12:24:09 +05:30
channels feat: Added the backend support for twilio content templates (#12272) 2025-08-24 10:05:15 +05:30
contacts feat: Bulk actions for contacts (#12763) 2025-10-30 15:28:28 +05:30
conversations chore: move UpdateMessageStatus to deferred queue (#11943) 2025-07-16 08:19:00 +05:30
crm feat: integrate LeadSquared CRM (#11284) 2025-04-29 09:14:00 +05:30
inboxes feat: Run assignment every 15 minutes (#12334) 2025-08-29 15:10:56 -07:00
internal feat: automate account deletion (#11406) 2025-05-23 12:58:13 +05:30
labels fix: Update associations when a label is updated (#3046) 2021-09-21 10:16:32 +05:30
migration feat: Backend - Companies API endpoint with pagination and search (#12840) 2025-11-18 14:28:56 +05:30
notification feat: Update last_snoozed_at after the un-snooze notification (#8943) 2024-02-20 18:55:39 +05:30
webhooks fix: Use contact_id instead of sender_id for Instagram message locks (#12841) 2025-11-12 16:56:52 +05:30
action_cable_broadcast_job.rb chore: Add more conversation events for reload (#10877) 2025-02-11 00:33:45 -08:00
application_job.rb chore: Improve active job error logs for deserialization error (#8742) 2024-01-18 19:27:18 +04:00
bulk_actions_job.rb feat: Add support for bulk snooze until (#9360) 2024-05-08 08:55:31 +05:30
contact_ip_lookup_job.rb feat(poc): Disable widget based on country (#6658) 2023-03-14 09:09:57 -07:00
conversation_reply_email_job.rb chore(sidekiq): log ActiveJob class and job_id on dequeue (#12704) 2025-10-22 20:20:37 -07:00
data_import_job.rb fix: stream attachment handling in workers (#12870) 2025-12-05 13:02:53 -08:00
delete_object_job.rb fix: Prevent SLA deletion timeouts by moving to async job (#12944) 2025-12-10 12:28:47 +05:30
event_dispatcher_job.rb chore: Reorganize Sidekiq Queues (#6976) 2023-05-04 15:44:16 +05:30
hook_job.rb feat: integrate LeadSquared CRM (#11284) 2025-04-29 09:14:00 +05:30
macros_execution_job.rb feat: Execute macro actions, for the conversation (#5066) 2022-07-26 12:41:22 +05:30
mutex_application_job.rb fix: mutex timeout and error handling (#8770) 2024-01-24 14:18:21 +04:00
send_on_slack_job.rb fix: mutex timeout and error handling (#8770) 2024-01-24 14:18:21 +04:00
send_reply_job.rb chore: Migrate mailers from the worker to jobs (#12331) 2025-10-21 16:36:37 -07:00
slack_unfurl_job.rb feat: Support link unfurling for all the channels within the same connected channel account. (#8033) 2023-10-08 17:55:03 +05:30
trigger_scheduled_items_job.rb feat: Add sidekiq jobs to monitor applied SLAs (#8828) 2024-02-07 21:44:56 +04:00
webhook_job.rb feat: Mark the messages as failed if the API channel webhooks fail for any reason. (#8277) 2023-11-04 12:26:28 +05:30