Skip to content

feat(integrations): add ActionScheduler group handling#4559

Merged
miguelpeixe merged 27 commits intotrunkfrom
feat/integrations-action-groups
Mar 23, 2026
Merged

feat(integrations): add ActionScheduler group handling#4559
miguelpeixe merged 27 commits intotrunkfrom
feat/integrations-action-groups

Conversation

@miguelpeixe
Copy link
Copy Markdown
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() and other methods with wp shell:
// Groups
print_r( Newspack\Action_Scheduler::get_all_groups() );
Array
(
    [0] => newspack
    [1] => newspack-integration-esp
)

print_r( Newspack\Action_Scheduler::get_group_labels() );
Array
(
    [newspack] => Newspack
    [newspack-integration-esp] => ESPs Integration
)

// Hooks
print_r( Newspack\Action_Scheduler::get_hooks() );
Array
(
    [0] => newspack_contact_sync_retry
    [1] => newspack_data_events_handle
)

// 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
Copy Markdown
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.

Comment thread includes/class-action-scheduler.php Outdated
Comment thread includes/class-action-scheduler.php
Comment thread includes/reader-activation/class-integrations.php
Comment thread tests/unit-tests/integrations/class-test-integrations.php
Copy link
Copy Markdown
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
@miguelpeixe miguelpeixe added the [Status] Needs Review The issue or pull request needs to be reviewed label Mar 19, 2026
Copy link
Copy Markdown
Contributor

@chickenn00dle chickenn00dle left a comment

Choose a reason for hiding this comment

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

Looks good! Thanks @miguelpeixe

Image

@github-actions github-actions Bot added [Status] Approved The pull request has been reviewed and is ready to merge and removed [Status] Needs Review The issue or pull request needs to be reviewed labels Mar 22, 2026
@miguelpeixe miguelpeixe merged commit 411732a into trunk Mar 23, 2026
9 checks passed
@miguelpeixe miguelpeixe deleted the feat/integrations-action-groups branch March 23, 2026 13:24
@github-actions
Copy link
Copy Markdown

Hey @miguelpeixe, good job getting this PR merged! 🎉

Now, the needs-changelog label has been added to it.

Please check if this PR needs to be included in the "Upcoming Changes" and "Release Notes" doc. If it doesn't, simply remove the label.

If it does, please add an entry to our shared document, with screenshots and testing instructions if applicable, then remove the label.

Thank you! ❤️

dkoo added a commit that referenced this pull request Mar 24, 2026
* feat(access-control): init premium newsletters wizard pages

* feat: adapt existing access control components for premium newsletters

* chore: remove redundant unnecessary component

* chore: rename variable for clarity

* Apply suggestions from code review

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

* chore: remove unnecessary REST route

* refactor: use tokenfield instead of checkboxes for newsletter lists

* feat: add advanced settings modal

* chore: rename config key for accuracy and set default to true

* chore(icons): replace lockDoor with contentLocked and emailPremium icons

* fix: premium newsletter UI fixes

* fix: show SectionHeader secondaryActions as dropdown menu

* fix: alignment of items in SectionHeader

* feat: link gate titles to edit pages for convenience

* fix: remove margin if form-token-field is the only child

* feat: rename menu item

* fix: move Gate Priority to menu instead of separate action

* fix: proposed new page layout for Institutions wizard

* fix: revert proposed Institutions page layout

* refactor: reorganize some Content_Gate class methods into new subclasses

* fix: advanced settings updates

* chore: update translation files [skip ci]

* feat(color-picker): simplify component to use basecontrol (#4581)

* chore: update translation files [skip ci]

* feat(components): add CardFeature component (#4583)

* chore: update translation files [skip ci]

* build(deps): bump google/auth from 1.42.0 to 1.50.1 (#4590)

Bumps [google/auth](https://github.com/googleapis/google-auth-library-php) from 1.42.0 to 1.50.1.
- [Release notes](https://github.com/googleapis/google-auth-library-php/releases)
- [Changelog](https://github.com/googleapis/google-auth-library-php/blob/main/CHANGELOG.md)
- [Commits](googleapis/google-auth-library-php@v1.42.0...v1.50.1)

---
updated-dependencies:
- dependency-name: google/auth
  dependency-version: 1.50.1
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* feat(integrations): add ActionScheduler group handling (#4559)

* chore: update translation files [skip ci]

* fix: don't clear content rule tokens from state when switching options

* fix: error handling for async requests

* fix: error handling via Notice in all access control view components

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Thomas Guillot <thomas@automattic.com>
Co-authored-by: matticbot <sysops+ghmatticbot@automattic.com>
Co-authored-by: Thomas Guillot <thomasguillot@users.noreply.github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Miguel Peixe <miguel.peixe@automattic.com>
dkoo added a commit that referenced this pull request Apr 1, 2026
…4589)

* feat(access-control): init premium newsletters wizard pages

* feat: adapt existing access control components for premium newsletters

* chore: remove redundant unnecessary component

* chore: rename variable for clarity

* Apply suggestions from code review

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

* chore: remove unnecessary REST route

* refactor: use tokenfield instead of checkboxes for newsletter lists

* feat: add advanced settings modal

* chore: rename config key for accuracy and set default to true

* chore(icons): replace lockDoor with contentLocked and emailPremium icons

* fix: premium newsletter UI fixes

* fix: show SectionHeader secondaryActions as dropdown menu

* fix: alignment of items in SectionHeader

* feat: link gate titles to edit pages for convenience

* fix: remove margin if form-token-field is the only child

* feat: rename menu item

* fix: move Gate Priority to menu instead of separate action

* fix: proposed new page layout for Institutions wizard

* fix: revert proposed Institutions page layout

* feat(access-control): filter available lists by content restrictions

* fix: potential fatal; move filter callback to Premium_Newsletters class

* refactor: reorganize some Content_Gate class methods into new subclasses

* fix: advanced settings updates

* chore: update translation files [skip ci]

* feat(color-picker): simplify component to use basecontrol (#4581)

* chore: update translation files [skip ci]

* feat(components): add CardFeature component (#4583)

* chore: update translation files [skip ci]

* build(deps): bump google/auth from 1.42.0 to 1.50.1 (#4590)

Bumps [google/auth](https://github.com/googleapis/google-auth-library-php) from 1.42.0 to 1.50.1.
- [Release notes](https://github.com/googleapis/google-auth-library-php/releases)
- [Changelog](https://github.com/googleapis/google-auth-library-php/blob/main/CHANGELOG.md)
- [Commits](googleapis/google-auth-library-php@v1.42.0...v1.50.1)

---
updated-dependencies:
- dependency-name: google/auth
  dependency-version: 1.50.1
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* feat(integrations): add ActionScheduler group handling (#4559)

* chore: update translation files [skip ci]

* fix: don't clear content rule tokens from state when switching options

* fix: error handling for async requests

* fix: error handling via Notice in all access control view components

* feat: auto-signup and remove readers from lists based on subscription

* refactor: no need for namespace due to use statement

* fix: filter user ID when rendering premium newsletter lists

* fix: delete renamed wizard file

* test: add unit tests for premium newsletters

* fix: remove Registered Access options for newsletters

* refactor: use evaluate_rules instead of custom logic for newsletter gates

* fix: use Content_Restriction_Control::is_post_restricted in maybe_add_or_remove_lists

* feat: debounce premium list updates via scheduled events

* feat: also schedule access check for email domain + reader data updates

* test: add tests for reader data and whitelisted email domains

* chore: update access check delay to 10 minutes

* chore: only filter restricted lists on front-end

* Update includes/content-gate/class-premium-newsletters.php

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* fix: add user ID to post/gate map cache

* Update includes/reader-activation/class-reader-activation.php

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* fix: avoid recursive data event loop for `reader_data_updated`

* fix: return empty array when no gates are found

* test: add tests for data event listeners

* Apply suggestions from code review

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* chore: fix docblock

* test: avoid fatal in case _get_cron_array() returns false

* refactor: simplify queue processing with recurring events

* test: fix unit tests

* chore: fix outdated inline comment

* chore: fix outdated inline comment

* fix: better control of newspack_content_restriction_control_user_id filter

* chore: outdated docblock

* refactor: feedback from PR

* refactor: use cron only for recurring access checks

* refactor: remove redundant Data Event listeners

* test: fix failing unit test

* test: remove failing test

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Thomas Guillot <thomas@automattic.com>
Co-authored-by: matticbot <sysops+ghmatticbot@automattic.com>
Co-authored-by: Thomas Guillot <thomasguillot@users.noreply.github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Miguel Peixe <miguel.peixe@automattic.com>
matticbot pushed a commit that referenced this pull request Apr 2, 2026
# [6.37.0-alpha.1](v6.36.1...v6.37.0-alpha.1) (2026-04-02)

### Bug Fixes

* **card-settings-group:** change default actionType from chevron to none ([#4610](#4610)) ([00505ed](00505ed))
* **post-date:** preserve classic theme markup and fix archive titles ([#4602](#4602)) ([c5fb825](c5fb825))
* remove removal of block visibility ([#4595](#4595)) ([9396379](9396379))

### Features

* **access-control:** filter available lists by content restrictions ([#4589](#4589)) ([959127f](959127f)), closes [#4581](#4581) [#4583](#4583) [#4590](#4590)
* **access-control:** premium newsletters UI ([#4577](#4577)) ([6f8c891](6f8c891)), closes [#4581](#4581) [#4583](#4583) [#4590](#4590)
* **author-profile-social:** add support for colors, block spacing, brand style ([#4509](#4509)) ([21cf4c9](21cf4c9))
* campaigns wizard light UI refresh ([#4588](#4588)) ([6078c4b](6078c4b))
* **color-picker:** simplify component to use basecontrol ([#4581](#4581)) ([ff677ea](ff677ea))
* **components:** add CardFeature component ([#4583](#4583)) ([5aabb18](5aabb18))
* **content-gate:** institution management ui ([#4582](#4582)) ([ae88750](ae88750))
* **content-gate:** institutional access redirect and loading UX ([#4593](#4593)) ([548d236](548d236))
* **content-gate:** institutions ([#4574](#4574)) ([49b0c05](49b0c05))
* **content-gate:** personalized institutional access verification page ([#4596](#4596)) ([0eed591](0eed591))
* **image-upload:** simplify component to use basecontrol; remove info prop ([#4580](#4580)) ([d51eb54](d51eb54))
* **integrations:** add ActionScheduler group handling ([#4559](#4559)) ([411732a](411732a))
* **integrations:** promoted fields for content gate and campaign segmentation ([#4601](#4601)) ([f943df2](f943df2))
* **newspack-ui:** add stack layout and color utility classes ([#4600](#4600)) ([1934067](1934067))
* **post-date:** centralize date features from theme into plugin ([#4579](#4579)) ([19f15eb](19f15eb))
* **sync:** prevent stale data on retry, improve logging and error handling ([#4562](#4562)) ([5467f34](5467f34))
* **tags:** add private tags feature ([#4507](#4507)) ([06d7711](06d7711))
* **yoast:** add primary category utility and settings toggle ([#4563](#4563)) ([4b396c3](4b396c3))
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 2, 2026

🎉 This PR is included in version 6.37.0-alpha.1 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

matticbot pushed a commit that referenced this pull request Apr 13, 2026
# [6.37.0](v6.36.3...v6.37.0) (2026-04-13)

### Bug Fixes

* **card-settings-group:** change default actionType from chevron to none ([#4610](#4610)) ([00505ed](00505ed))
* **post-date:** preserve classic theme markup and fix archive titles ([#4602](#4602)) ([c5fb825](c5fb825))
* remove removal of block visibility ([#4595](#4595)) ([9396379](9396379))

### Features

* **access-control:** filter available lists by content restrictions ([#4589](#4589)) ([959127f](959127f)), closes [#4581](#4581) [#4583](#4583) [#4590](#4590)
* **access-control:** premium newsletters UI ([#4577](#4577)) ([6f8c891](6f8c891)), closes [#4581](#4581) [#4583](#4583) [#4590](#4590)
* **author-profile-social:** add support for colors, block spacing, brand style ([#4509](#4509)) ([21cf4c9](21cf4c9))
* campaigns wizard light UI refresh ([#4588](#4588)) ([6078c4b](6078c4b))
* **color-picker:** simplify component to use basecontrol ([#4581](#4581)) ([ff677ea](ff677ea))
* **components:** add CardFeature component ([#4583](#4583)) ([5aabb18](5aabb18))
* **content-gate:** institution management ui ([#4582](#4582)) ([ae88750](ae88750))
* **content-gate:** institutional access redirect and loading UX ([#4593](#4593)) ([548d236](548d236))
* **content-gate:** institutions ([#4574](#4574)) ([49b0c05](49b0c05))
* **content-gate:** personalized institutional access verification page ([#4596](#4596)) ([0eed591](0eed591))
* **image-upload:** simplify component to use basecontrol; remove info prop ([#4580](#4580)) ([d51eb54](d51eb54))
* **integrations:** add ActionScheduler group handling ([#4559](#4559)) ([411732a](411732a))
* **integrations:** promoted fields for content gate and campaign segmentation ([#4601](#4601)) ([f943df2](f943df2))
* **newspack-ui:** add stack layout and color utility classes ([#4600](#4600)) ([1934067](1934067))
* **post-date:** centralize date features from theme into plugin ([#4579](#4579)) ([19f15eb](19f15eb))
* **sync:** prevent stale data on retry, improve logging and error handling ([#4562](#4562)) ([5467f34](5467f34))
* **tags:** add private tags feature ([#4507](#4507)) ([06d7711](06d7711))
* **yoast:** add primary category utility and settings toggle ([#4563](#4563)) ([4b396c3](4b396c3))
@github-actions
Copy link
Copy Markdown

🎉 This PR is included in version 6.37.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Status] Approved The pull request has been reviewed and is ready to merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants