Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix multiple scheduled update sync issue #37266

Merged
merged 7 commits into from
May 8, 2024
Merged

Conversation

zaerl
Copy link
Contributor

@zaerl zaerl commented May 7, 2024

Fixes sync issues in the wpcom/v2/update-schedules endpoints.

Proposed changes:

  • Add the jetpack_scheduled_plugins_update_sync filter that can prevent updating jetpack_scheduled_plugins_update option
  • Block sync during the delete phase found in WPCOM_REST_API_V2_Endpoint_Update_Schedules::update_item

Other information:

  • Have you written new tests for your changes, if applicable?
  • Have you checked the E2E test CI results, and verified that your changes do not break them?
  • Have you tested your changes on WordPress.com, if applicable (if so, you'll see a generated comment below with a script to run)?

Jetpack product discussion

Does this pull request change what data or activity we track or use?

No.

Testing instructions:

  • Install fix/su-multiple-sync-issue in WordPress.com Features
  • Be sure to have needed jobs sandboxed and the watcher running
  • Add the code found in pcmemI-2Ww-p2 at "Monitoring Jetpack syncs" section
  • Leave tail -f -n 40 /tmp/php-errors open

On https://wordpress.com/plugins/scheduled-updates/__BLOG__

  1. Create a scheduled update.
  2. Update it without changing plugins.
  3. Delete it.
  4. Add other scheduled updates.
  5. Change plugins.
  6. Etc.

The jetpack_scheduled_plugins_update string should appear three times in your logs. Perform other tests. The sync count should always be:

  1. Read: 0
  2. Create: +1
  3. Update: +1
  4. Delete: +1

Ensure the is always on sync using wpsh:

switch_to_blog(__BLOG_ID__);
print_r( get_option('jetpack_scheduled_plugins_update') );

@zaerl zaerl marked this pull request as draft May 7, 2024 15:19
Copy link
Contributor

github-actions bot commented May 7, 2024

Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.

  • To test on WoA, go to the Plugins menu on a WordPress.com Simple site. Click on the "Upload" button and follow the upgrade flow to be able to upload, install, and activate the Jetpack Beta plugin. Once the plugin is active, go to Jetpack > Jetpack Beta, select your plugin, and enable the fix/su-multiple-sync-issue branch.

    • For jetpack-mu-wpcom changes, also add define( 'JETPACK_MU_WPCOM_LOAD_VIA_BETA_PLUGIN', true ); to your wp-config.php file.
  • To test on Simple, run the following command on your sandbox:

    bin/jetpack-downloader test jetpack-mu-wpcom-plugin fix/su-multiple-sync-issue
    

Interested in more tips and information?

  • In your local development environment, use the jetpack rsync command to sync your changes to a WoA dev blog.
  • Read more about our development workflow here: PCYsg-eg0-p2
  • Figure out when your changes will be shipped to customers here: PCYsg-eg5-p2

Copy link
Contributor

github-actions bot commented May 7, 2024

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • ✅ Add a "[Status]" label (In Progress, Needs Team Review, ...).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖


The e2e test report can be found here. Please note that it can take a few minutes after the e2e tests checks are complete for the report to be available.


Once your PR is ready for review, check one last time that all required checks appearing at the bottom of this PR are passing or skipped.
Then, add the "[Status] Needs Team Review" label and ask someone from your team review the code. Once reviewed, it can then be merged.
If you need an extra review from someone familiar with the codebase, you can update the labels from "[Status] Needs Team Review" to "[Status] Needs Review", and in that case Jetpack Approvers will do a final review of your PR.

@github-actions github-actions bot added the [Status] Needs Author Reply We would need you to make some changes or provide some more details about your PR. Thank you! label May 7, 2024
@zaerl zaerl marked this pull request as ready for review May 8, 2024 08:41
@zaerl zaerl self-assigned this May 8, 2024
@zaerl zaerl requested a review from a team May 8, 2024 09:16
Copy link
Contributor

@TimBroddin TimBroddin left a comment

Choose a reason for hiding this comment

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

Awesome work!

@zaerl zaerl merged commit d928d58 into trunk May 8, 2024
54 checks passed
@zaerl zaerl deleted the fix/su-multiple-sync-issue branch May 8, 2024 09:55
@github-actions github-actions bot removed [Status] Needs Author Reply We would need you to make some changes or provide some more details about your PR. Thank you! [Status] In Progress labels May 8, 2024
@@ -195,6 +202,11 @@ public static function delete_scheduled_update( $timestamp, $plugins ) {
* Save the schedules for sync after cron option saving.
*/
public static function update_option_cron() {
// Do not update the option if the filter returns false.
if ( ! apply_filters( self::PLUGIN_CRON_SYNC_HOOK, true ) ) {
Copy link
Member

Choose a reason for hiding this comment

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

@zaerl Let's add hook docs to this for future reference.

How would you feel about using the hook string directly rather than abstracting it into a constant?
Feels to me like an opportunity to improve readability and debug-ability over DRY-ness.

pkuliga pushed a commit that referenced this pull request May 9, 2024
* Add cron changing filter

* changelog

* Add base test

* Add unit tests

* Remove debug code

* Add new unit tests

* Fix: typo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants