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

[2.1] - Add command to view mview state and queue #12050

Merged
merged 12 commits into from
Dec 11, 2017

Conversation

convenient
Copy link
Contributor

@convenient convenient commented Nov 5, 2017

Description

This is similar to the magerun1 command here: netz98/n98-magerun#891

I like the ability to view the mview queue in realtime as its being processed, it can be quite helpful when debugging indexing issues.

This command will actually show how many items are in the list pending processing, as well information from the mview_state table.

php bin/magento indexer:status:mview
+---------------------------+----------+--------+---------------------+------------+---------+
| ID                        | Mode     | Status | Updated             | Version ID | Backlog |
+---------------------------+----------+--------+---------------------+------------+---------+
| catalog_category_product  | enabled  | idle   | 2017-11-02 10:00:00 | 1          | 0       |
| catalog_product_attribute | enabled  | idle   | 2017-11-02 10:00:00 | 1          | 1       |
| catalog_product_category  | disabled | idle   | 2017-11-02 10:00:00 | 1          | 0       |
| catalog_product_price     | enabled  | idle   | 2017-11-02 10:00:00 | 1          | 0       |
+---------------------------+----------+--------+---------------------+------------+---------+

screen shot 2017-11-05 at 20 47 47

Manual testing scenarios

  1. Enable an indexer php bin/magento indexer:set-mode schedule catalog_product_price
  2. Trigger an action on the product price that will update the _cl table
  3. Run php bin/magento indexer:status:mview to see the backlog increase
  4. magerun2 sys:cron:run indexer_update_all_views will trigger the mview processes
  5. See the backlog decrease

Contribution checklist

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • All automated tests passed successfully (all builds on Travis CI are green)

This is similar to the magerun1 command here: netz98/n98-magerun#891

I like the ability to view the mview queue in realtime as its being processed, it can be quite helpful when debugging indexing issues.

This command will actually show how many items are in the list pending processing, as well information from the `mview_state` table.

```
php bin/magento indexer:status:mview
+---------------------------+----------+--------+---------------------+------------+---------+
| ID                        | Mode     | Status | Updated             | Version ID | Backlog |
+---------------------------+----------+--------+---------------------+------------+---------+
| catalog_category_product  | enabled  | idle   | 2017-11-02 10:00:00 | 1          | 0       |
| catalog_product_attribute | enabled  | idle   | 2017-11-02 10:00:00 | 1          | 1       |
| catalog_product_category  | disabled | idle   | 2017-11-02 10:00:00 | 1          | 0       |
| catalog_product_price     | enabled  | idle   | 2017-11-02 10:00:00 | 1          | 0       |
+---------------------------+----------+--------+---------------------+------------+---------+
```

I'll point this PR into 2.1.x and raise a separate PR to pop it into 2.2.x.
@convenient convenient force-pushed the 2-1-0-mview-list branch 2 times, most recently from 9ca0c5c to e08cc35 Compare November 6, 2017 09:01
@ihor-sviziev
Copy link
Contributor

Really good idea. Would be great to have something similar in the magento admin.

@convenient
Copy link
Contributor Author

Would be great to have something similar in the magento admin

@ihor-sviziev That would definitely be neat, however I'll focus on getting this command and potentially deal with admin UI in a separate PR at a later.

private $mviewIndexersCollection;

public function __construct(
\Magento\Framework\Mview\View\CollectionInterface $collection
Copy link
Contributor

Choose a reason for hiding this comment

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

You need to use \Magento\Framework\Mview\View\CollectionFactory there. Also would be great to import this class.

}

$rows[] = [
$indexer->getData('view_id'),
Copy link
Contributor

Choose a reason for hiding this comment

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

Would be better to use $indexer->getId()

$rows = [];

/** @var \Magento\Framework\Mview\View $indexer */
foreach ($this->mviewIndexersCollection as $indexer) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Actually it's not indexer, it's view. So it's better to use one name for this object type


$rows[] = [
$indexer->getData('view_id'),
$state->getData('mode'),
Copy link
Contributor

Choose a reason for hiding this comment

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

$state->getMode()

$rows[] = [
$indexer->getData('view_id'),
$state->getData('mode'),
$state->getData('status'),
Copy link
Contributor

Choose a reason for hiding this comment

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

$state->getStatus()

$indexer->getData('view_id'),
$state->getData('mode'),
$state->getData('status'),
$state->getData('updated'),
Copy link
Contributor

Choose a reason for hiding this comment

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

$state->getUpdated()

$state->getData('mode'),
$state->getData('status'),
$state->getData('updated'),
$state->getData('version_id'),
Copy link
Contributor

Choose a reason for hiding this comment

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

$state->getVersionId()

@convenient
Copy link
Contributor Author

Thanks for the review @ihor-sviziev I'll action these later.

Quick Q: why is it your preference to use $obj->getFoo() rather than $obj->getData('foo') ? I've a personal dislike for those magic methods but it'd just a style thing for me. Is this to keep it more inline with the rest of M2?

@ihor-sviziev
Copy link
Contributor

ihor-sviziev commented Nov 6, 2017 via email

@convenient
Copy link
Contributor Author

@ihor-sviziev thank you for the clarification, you were right I was not considering the interface.

i've updated the PR to address your concerns and the test suite is green, please review.

@ishakhsuvarov ishakhsuvarov self-assigned this Nov 8, 2017
@ishakhsuvarov ishakhsuvarov added this to the November 2017 milestone Nov 8, 2017
@convenient
Copy link
Contributor Author

Cool, now that this is going green I'll port it to 2.2.

@convenient
Copy link
Contributor Author

Done. Raised #12122 for the 2.2 series.

@convenient convenient changed the title Add command to view mview state and queue [2.1] - Add command to view mview state and queue Nov 8, 2017
@okorshenko okorshenko assigned okorshenko and unassigned okorshenko Nov 8, 2017
@convenient
Copy link
Contributor Author

FYI I'll not do any further work on this PR until everyone's happy with the changes and discussion that will be happening in #12122 .

@magento-team magento-team merged commit 49812be into magento:2.1-develop Dec 11, 2017
magento-team pushed a commit that referenced this pull request Dec 11, 2017
[EngCom] Public Pull Requests - 2.1-develop
 - MAGETWO-85180: [Backport 2.1-develop] Fix swagger-ui on instances of Magento running on a non-standard port #12579
 - MAGETWO-85097: [Backport-2.1] Added namespace to product videos fotorama events #12558
 - MAGETWO-83478: Add command to view mview state and queue #12050
@convenient convenient deleted the 2-1-0-mview-list branch December 18, 2017 09:49
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.

6 participants