Skip to content

feat(integrations): add ActionScheduler group handling#4559

Open
miguelpeixe wants to merge 21 commits intotrunkfrom
feat/integrations-action-groups
Open

feat(integrations): add ActionScheduler group handling#4559
miguelpeixe wants to merge 21 commits intotrunkfrom
feat/integrations-action-groups

Conversation

@miguelpeixe
Copy link
Member

@miguelpeixe miguelpeixe commented Mar 11, 2026

All Submissions:

Changes proposed in this Pull Request:

Separates Newspack's AS actions into dedicated groups so each integration and subsystem can be identified and queried. Because AS has a separate wp_actionscheduler_groups table, we can safely find existing groups using a wildcard search before querying the actions table with indexed groups.

  • Each integration's actions now run under newspack-integration-{$integration_id}, covering handler retries, sync retries, and async contact pulls*
  • Webhooks use newspack-webhooks, bulk admin syncs use newspack-sync
  • A new Action_Scheduler utility class centralizes group constants and provides reusable query helpers for fetching actions across all Newspack groups

*The first run of a data event handler cannot be in an integration group because a single data event dispatch runs all handlers in a single AS action. Only retries spin an action for a single handler. The same goes for syncs, which don't run as an AS action until it requires a retry.

How to test the changes in this Pull Request:

  1. Update your ESP configuration with an invalid key
  2. Register as a new reader
  3. In the ActionScheduler admin (WooCommerce -> Status -> Scheduled Actions), verify the retry action appears under the newspack-integration-esp group rather than the generic newspack group.
  4. Test the get_scheduled_actions() APIs with wp shell:
// All Newspack-related actions
print_r( Newspack\Action_Scheduler::get_scheduled_actions() );

// Tweak query args
print_r( Newspack\Action_Scheduler::get_scheduled_actions( [ 'per_page' => 2, 'offset' => 2 ] ) );
print_r( Newspack\Action_Scheduler::get_scheduled_actions( [ 'status' => 'failed' ] ) );

// All integrations actions
print_r( Newspack\Reader_Activation\Integrations::get_scheduled_actions() );

// All ESP actions
$esp = Newspack\Reader_Activation\Integrations::get_integration( 'esp' );
print_r( $esp->get_scheduled_actions() );

Other information:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes, as applicable?
  • Have you successfully ran tests with your changes locally?

Copy link
Contributor

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 introduces Action Scheduler “group” namespacing for Newspack so scheduled actions can be attributed and queried per integration/subsystem, and adds helper APIs to query those actions.

Changes:

  • Assign integration-specific Action Scheduler groups (e.g. newspack-integration-{$integration_id}) for retries and async contact pulls.
  • Move other subsystems to dedicated groups (e.g. newspack-webhooks, newspack-sync) and update affected scheduling calls/tests.
  • Add a new Newspack\Action_Scheduler utility class plus new query helpers on Integrations/Integration.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
tests/unit-tests/reader-activation-sync.php Updates assertions to look for per-integration AS groups.
tests/unit-tests/integrations/class-test-integrations.php Adds unit tests for group-resolution helpers and filter behavior.
includes/reader-activation/sync/class-contact-sync.php Schedules integration retry actions under integration-specific groups.
includes/reader-activation/sync/class-contact-sync-admin.php Schedules bulk admin sync actions under a dedicated newspack-sync group.
includes/reader-activation/integrations/class-integration.php Adds get_action_group() and get_scheduled_actions() convenience methods.
includes/reader-activation/integrations/class-contact-pull.php Schedules async pulls under integration-specific groups and dedupes by that group.
includes/reader-activation/class-integrations.php Adds group helpers, handler->group filter, and integration-scoped scheduled action querying.
includes/data-events/class-webhooks.php Moves webhook AS actions to newspack-webhooks group.
includes/data-events/class-data-events.php Adds filterable handler group resolution and uses it for handler retries/default dispatch group.
includes/class-newspack.php Ensures the new Action Scheduler helper file is included.
includes/class-action-scheduler.php Introduces a DB-backed helper for listing groups by prefix and querying actions by group(s).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Copy link
Contributor

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

Copilot reviewed 11 out of 11 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

@miguelpeixe miguelpeixe marked this pull request as ready for review March 11, 2026 22:16
@miguelpeixe miguelpeixe requested a review from a team as a code owner March 11, 2026 22:16
@miguelpeixe miguelpeixe self-assigned this Mar 11, 2026
@miguelpeixe miguelpeixe requested a review from leogermani March 11, 2026 22:17
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