klaviyo / magento2-klaviyo

37 stars 51 forks source link

ATC bug fixes, updated cleanup crons, enforce payload size #215

Closed cykolln closed 1 year ago

cykolln commented 1 year ago

Description

This PR encompasses several improvements for the added to cart event. Namely it enforces the payload size, and doesn't allow for rows with truncated payload to be committed to the database.

Previously, truncated Added to Cart payloads would raise unhandled exceptions when processing in both Cron/EventsTopic.php and Cron/KlSyncs.php, which in turn would prevent the processing of the remaining rows. The unhandled exceptions also prevented the rows that were able to move over to the kl_sync table from being marked as MOVED, leading to repetitive processing and continuous retries. This PR adds exception handling which will log the exception and mark any rows that raise exceptions during processing as FAILED. The cleanup crons have been adjusted to additionally delete FAILED rows from both the kl_events table and the kl_sync table. Previously these rows would remain indefinitely.

These fixes are intended to prevent truncated payloads for future events and clear out failed events from the database. Future improvements will be made to further optimize the Added to Cart event.

Manual Testing Steps

  1. Pre-change, recreated the issue with truncated payloads. Triggered a variety of Added to Cart events, some with truncated payloads, some without.
  2. After changes, verified that an event with a payload exceeding the maximum character count would not be added to the kl_events table and that a log was created.
  3. Verified that the klaviyo_events_topic cron processed all rows - marking those with existing truncated payloads as FAILED and marking all rows with valid payloads as MOVED.
  4. Verified that the klaviyo_webhook/event_sync cron processed all rows - marking those with truncated payloads as failed.
  5. Verified that the 2 cleanup crons removed rows marked as FAILED for both tables, as well as MOVED for kl_events and SYNCED for kl_sync.

Pre-Submission Checklist:

klaviyobot commented 1 year ago

https://klaviyo.tpondemand.com/entity/148589

klaviyobot commented 1 year ago

https://klaviyo.tpondemand.com/entity/148590