Skip to content

Conversation

BrianHenryIE
Copy link
Contributor

Proposed changes

Previously, if there was a failure sending the events, e.g. connection failure, 500, the call to BatchQueue::increment_attempt() never ran.

This PR moves that call to happen before sending the event is attempted.

Type of Change

Production

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Dependency update
  • Refactoring / housekeeping (changes to files not directly related to functionality)

Development

  • Tests
  • Dependency update
  • Environment update / refactoring
  • Documentation Update

Video

Checklist

  • I have read the CONTRIBUTING doc
  • I have viewed my change in a web-browser
  • Linting and tests pass locally with my changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)

Further comments

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors EventManager and Data to support dependency injection of the event queue, moves the call to increment_attempt so it runs before each batch send attempt, and updates tests to use mocks instead of Patchwork redefines. It also adjusts the default attempt count for pageview events in BatchQueue and adds an integration test for retry logic.

  • Inject EventQueue into EventManager and Data, replacing static calls
  • Call increment_attempt at the start of send_saved_events_batch
  • Update PHPUnit tests to mock EventQueue and EventManager directly
  • Adjust default attempts for "pageview" events in BatchQueue
  • Add an integration test verifying retry limits

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
includes/EventManager.php Added constructor injection, replaced static queue calls, moved increment_attempt earlier in batch send
includes/Data.php Accepts injected EventManager instead of instantiating internally
includes/EventQueue/Queues/BatchQueue.php Set pageview events to 0 initial attempts, updated comment
includes/HiiveConnection.php Improved docblock types for connect parameters
tests/phpunit/includes/EventManagerTest.php Refactored tests to use injected EventQueue mocks
tests/phpunit/includes/DataTest.php Updated tests to inject EventManager mocks
tests/integration/EventManagerIntegrationTest.php New integration test for batch retry behavior
Comments suppressed due to low confidence (2)

includes/EventQueue/Queues/BatchQueue.php:89

  • Add a unit test to verify that events with key 'pageview' initialize attempts to 0 and are not sent synchronously, ensuring this conditional behavior is covered.
'pageview' === $event->key ? 0 : 1

includes/EventManager.php:52

  • [nitpick] The property $queue is ambiguous alongside $event_queue; consider renaming it to $pendingEvents or similar to clarify its purpose.
private $queue = array();

Copy link
Contributor

@BrianHenryIE BrianHenryIE merged commit e00cfdb into main May 20, 2025
14 checks passed
@BrianHenryIE BrianHenryIE deleted the fix/PRESS7-375-fix-retry-logic branch May 20, 2025 16:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants