Skip to content

Sync: CLI: First pass at adding sync CLI commands#5933

Merged
gravityrail merged 12 commits intomasterfrom
update/wp-command-sync
Dec 19, 2016
Merged

Sync: CLI: First pass at adding sync CLI commands#5933
gravityrail merged 12 commits intomasterfrom
update/wp-command-sync

Conversation

@ebinnion
Copy link
Copy Markdown
Contributor

@ebinnion ebinnion commented Dec 16, 2016

For our ATAT work on WP.com, it is necessary that we have the ability to script a full sync. This PR introduces a handful of commands that should be useful to @seanosh for ATAT work.

Here are the commands to test:

  • wp jetpack sync status
    • This command retrieves the current sync status. The best way to test this is:
      • Go to REST api console and make a request to POST /sites/$site/sync
      • Immediately run wp jetpack sync status on your site to make sure that the status updates
  • wp jetpack sync start
    • Run this command on your host
    • Go to the REST api console, and run GET /sites/$site/sync/status a few times and verify that the status changes
  • wp jetpack sync start --modules=functions
    • Run this command on your host
    • Go to the REST api console, and run GET /sites/$site/sync/status and verify that functions is the only thing in config property.
  • wp jetpack sync_queue incremental peek
    • This command will likely return Nothing is in the sync queue
  • wp jetpack sync sync_queue full peek
    • Go to REST API console and trigger a POST /sites/$site/sync
    • Immediately run wp jetpack sync sync_queue full peek and you should see things in the queue
    • Note: This command only shows the top 100 things. In the future we could perhaps add paging? But, I don't think that's necessary for this first pass

}

public function sync( $args, $assoc_args ) {
if ( ! Jetpack::is_active() ) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think it would be great to check if other conditions for sync are meet. See sync_allowed method in https://github.com/Automattic/jetpack/blob/master/sync/class.jetpack-sync-actions.php#L91


switch ( $action ) {
case 'status':
require_once JETPACK__PLUGIN_DIR . 'sync/class.jetpack-sync-modules.php';
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could we reuse some of the sync status endpoint code by calling from it directly. Since it almost looks identical?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

For the status command, I think we could easily make that happen. We'd need to refactor a bit to handle the wp jetpack sync queue and wp jetpack sync start commands though.

@enejb
Copy link
Copy Markdown
Member

enejb commented Dec 16, 2016

I really like this and can see how sites would use this when they do batch operations to make sure things are in sync.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Let's add some documentation to this command, so that wp jetpack sync --help will be helpful :)

If you follow the syntax of one of the other commands, you should get a nice helpful message back

Copy link
Copy Markdown
Contributor

@dereksmart dereksmart Dec 16, 2016

Choose a reason for hiding this comment

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

just ! empty() will suffice for checking the variable. Won't throw a notice if not defined.

@ebinnion ebinnion force-pushed the update/wp-command-sync branch from 3b601fb to c6a4e38 Compare December 16, 2016 20:06
@ebinnion ebinnion added [Status] Needs Review This PR is ready for review. and removed [Status] In Progress labels Dec 16, 2016
'full_queue_next_sync' => ( $sender->get_next_sync_time( 'full_sync' ) - microtime( true ) ),
)
);
return Jetpack_Sync_Actions::get_sync_status();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

❤️

@lezama
Copy link
Copy Markdown
Contributor

lezama commented Dec 17, 2016

Great work @ebinnion

I think is ready to merge.

I am just not sure about the syntax for wp jetpack sync_queue incremental peek, maybe wp jetpack sync peek --queue=incremental --num=100 would make more sense?

@ebinnion
Copy link
Copy Markdown
Contributor Author

ebinnion commented Dec 19, 2016

Good point. The reason I created a separate command for the queue, sync_queue instead of sync, is that we could benefit from the robust validation of WP Cli thorough the @synopsis argument. When we put all of the sync related stuff under the sync method, the @synopsis argument felt awkward to me.

}

static function get_sync_status() {
require_once JETPACK__PLUGIN_DIR . 'sync/class.jetpack-sync-modules.php';
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

These first few lines could be written as:

self::initialize_sender();
$queue = self::$sender->get_sync_queue();
//...

@gravityrail gravityrail merged commit b99224e into master Dec 19, 2016
@gravityrail gravityrail deleted the update/wp-command-sync branch December 19, 2016 20:18
@gravityrail gravityrail removed the [Status] Needs Review This PR is ready for review. label Dec 19, 2016
@dereksmart dereksmart restored the update/wp-command-sync branch December 20, 2016 14:03
@dereksmart
Copy link
Copy Markdown
Contributor

4.5 0525012

jeherve added a commit that referenced this pull request Dec 21, 2016
dereksmart pushed a commit that referenced this pull request Jan 17, 2017
Changelog: add #5867

Changelog: add #5874

Changelog: add #5905

Changelog: add #5906

Changelog: add #5931

Changelog: add #5933

Changelog: add #5934
dereksmart pushed a commit that referenced this pull request Jan 17, 2017
Changelog: add #5867

Changelog: add #5874

Changelog: add #5905

Changelog: add #5906

Changelog: add #5931

Changelog: add #5933

Changelog: add #5934

Bring over 4.4.2 changelog from branch-4.4

@see 18012a3

Changelog: add #5976, #5978, #5983

Changelog: add #5917

Changelog: add #5832

Changelog: add 4.4.2 release post link.

CHangelog: add #5457

Changelog: add #5487

Changelog: add #5708

Changelog: add #5879

Changelog: add #5932

Changelog: add #5963

Changelog: add #5968

Changelog: add #5996

Changelog: add #5998

Changelog: add #5999

Changelog: add #6012

Changelog: add #6013

Changelog: add #6014

Changelog: add #6015

Changelog: add #6023

Changelog: add #6024

Changelog: add #6030

Changelog: add #5465

CHangelog: add #6063

Changelog: add #6025

Changelog: add #5974

Changelog: add #6059

Changelog: add #6046

Changelog: add #5418

Changelog: move things around and add missing information.

Changelog: add #5565

Changelog: add #6087

Changelog: add #6095

Readme: add @tyxla to the list of contributors.

Improved changelog for your readability and enjoyment

updated the release date

finalizing the changelog with a few more edits
$items = $queue->peek( 100 );

if ( empty( $items ) ) {
WP_CLI::log( sprintf( __( 'Nothing is in the %s queue', 'jetpack' ), $queue_name ) );
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please don't create translatable strings like that. incremental and full can be integrated like that in English but this doesn't work for other languages, also translators need to know what the placeholder is (hint: translators: comment :) ). A string that works for a construct like you were using: Nothing is in the queue: %s

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.

7 participants