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

Switch Admin UI to generating in batches, using WC's BatchProcessor tool #136

Merged
merged 7 commits into from
Jun 14, 2024

Conversation

coreymckrill
Copy link
Contributor

@coreymckrill coreymckrill commented Jun 14, 2024

Changes proposed in this Pull Request:

This changes the approach to generating stuff used in the admin UI. Instead of creating a separate Action Scheduler event for every product or order that should get generated, it leverages the batch methods introduced in #125 (and refined by subsequent PRs) to generate batches of items in one event. It also makes use of WooCommerce's BatchProcessor tool to handle batch management when more than one batch is needed (if you want to generate hundreds of products, for example).

To go along with this improved background generation process, this makes some improvements to the UI on the Smooth Generator page in WP Admin. It adds a progress bar while a generation job is running, which is updated periodically via WP's heartbeat system. Plus some other miscellaneous tweaks to improve the UX of the page.

Fixes #121

How to test the changes in this Pull Request:

  1. Navigate to Tools > Smooth Generator. Click one of the buttons to generate either 10 products or 10 orders. The page should reload and now show you a progress bar in its indeterminate mode. The "Generate" buttons on the page should now be disabled, and the "Cancel" button should be enabled. It may take a minute or two before the Action Scheduler job starts running in the background, but then the bar should change to show the job is complete. Watch the music video while you wait (if you end up with Michael Jackson's Smooth Criminal video, I'm sorry it's so weird). When the job is complete, the buttons should toggle so that "Generate" is enabled again, and "Cancel" is disabled.
  2. Now try doing a much larger batch so that you will actually get to see a partially filled progress bar. Try generating something like 1,000 products. It might take a minute or two once again to get started, but then you should see a partially filled progress bar. It shouldn't take too much longer after that to complete, since it will be doing batches of 100 at a time.
  3. Initiate another generation job, and cancel it. Go to Tools > Scheduled Actions and make sure the event really is gone.

Changelog entry

Improve background generation tasks initiated through the WP Admin UI.

@coreymckrill coreymckrill self-assigned this Jun 14, 2024
This way the progress bar will still update even
when the browser window is not focused.
@coreymckrill coreymckrill requested a review from barryhughes June 14, 2024 19:05
@coreymckrill coreymckrill marked this pull request as ready for review June 14, 2024 19:06
Copy link
Member

@barryhughes barryhughes left a comment

Choose a reason for hiding this comment

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

Great work!

Approving. This could be merged right away but I left some mostly optional comments/nits that I thought you should see first of all.

A few other observations (not all are directly related to your work here, though I thought they were worth jotting down):

  • Partly because of my settings, I found that generating a lot of products was bottle-necked by the slew of woocommerce_run_product_attribute_lookup_update_callback jobs that were consequently created. Perhaps this will be addressed by other work in progress for WC Core, however.
  • If I generate a set of products, then that control is disabled while product generation is in progress ... but the order generation button is also enabled. I'm not sure if this is deliberate, but I do think it could be handy for users to be able to set both in motion (whether or not the work happens concurrently, it would save them from having to remember to check back in and trigger the second piece of work).

Again, not stuff to address here, just capturing the thoughts.

Thank you, @coreymckrill!

includes/Admin/Settings.php Outdated Show resolved Hide resolved
includes/Admin/Settings.php Outdated Show resolved Hide resolved
includes/Admin/Settings.php Outdated Show resolved Hide resolved
includes/Admin/Settings.php Outdated Show resolved Hide resolved
includes/Admin/Settings.php Show resolved Hide resolved
includes/Router.php Outdated Show resolved Hide resolved
Comment on lines +72 to +77
<progress
id="smoothgenerator-progress-bar"
max="<?php echo esc_attr( $current_job->amount ); ?>"
value="<?php echo $current_job->processed ? esc_attr( $current_job->processed ) : ''; ?>"
style="width: 560px;"
>
Copy link
Member

Choose a reason for hiding this comment

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

Very snazzy! 🎷

includes/Admin/Settings.php Show resolved Hide resolved
@coreymckrill
Copy link
Contributor Author

I found that generating a lot of products was bottle-necked by the slew of woocommerce_run_product_attribute_lookup_update_callback jobs that were consequently created. Perhaps this will be addressed by other work in progress for WC Core, however.

🤔 I wonder if it would be worth disabling that lookup table altogether when we start a product generation process. And then re-enabling it afterward? Maybe that would cause other issues? I guess maybe it would depend on what kind of testing you were planning to do with the products...

If I generate a set of products, then that control is disabled while product generation is in progress ... but the order generation button is also enabled. I'm not sure if this is deliberate, but I do think it could be handy for users to be able to set both in motion (whether or not the work happens concurrently, it would save them from having to remember to check back in and trigger the second piece of work).

I think you mean the order generation button is also disabled? That's how it should be anyhow. Yeah, having multiple concurrent generation background tasks would probably be a nice enhancement, especially since you can already kind of do that with the CLI. Maybe something we could look at doing during #120

@coreymckrill coreymckrill merged commit 5b764d7 into trunk Jun 14, 2024
@barryhughes
Copy link
Member

I wonder if it would be worth disabling that lookup table altogether when we start a product generation process. And then re-enabling it afterward? Maybe that would cause other issues?

The same train of thoughts was going through my head. I'm not really sure what's best. Also not directly related to this work, so 🤷🏼

@barryhughes
Copy link
Member

I think you mean the order generation button is also disabled?

It's Friday and I can no longer type correctly, but yes. Thank you for logging it!

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.

Admin UI: Enable batch generation
2 participants