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

Product Statuses - Handle failure of the Update Product Statuses Job #2271

Merged

Conversation

jorgemd24
Copy link
Contributor

Changes proposed in this Pull Request:

Follow-up of #2257.

Part of #2146 & #2250

Since we're calculating product statuses using AS jobs, there's a possibility that the job might fail when attempting to retrieve or update the data. Therefore, it's important to store this error so we can notify the client about any issues while updating the product statuses.

Action Scheduler will retry the job, and if it succeeds, the process will continue as usual and the error message will be overridden once all statuses are completed.

However, if the job fails permanently and the failure rate exceeds the threshold, AS will stop the job. In this case, when the client requests the data via GET wc/gla/mc/product-statistics, the response will contain the error message.

{
    "timestamp": 1708537779,
    "statistics": {},
    "scheduled_sync": 0,
    "loading": false,
    "error": "My fatal error"
}

Detailed test instructions:

  1. Produce an error in purpose, for example, add the following line throw new \Error('My fatal error'); in
    public function get_product_view_report( $next_page_token = null ): array {
  2. Make a request to GET wc/gla/mc/product-statistics/refresh
  3. Go to WooCommerce -> Statuses -> Scheduled Actions and search for gla/jobs/update_merchant_product_statuses/process_item and see that the jobs fails.
  4. Call wc/gla/mc/product-statistics and see that the error is present in the transient.

Additional details:

Changelog entry

@jorgemd24 jorgemd24 self-assigned this Feb 21, 2024
@github-actions github-actions bot added changelog: add A new feature, function, or functionality was added. type: enhancement The issue is a request for an enhancement. labels Feb 21, 2024
Copy link

codecov bot commented Feb 21, 2024

Codecov Report

Attention: 7 lines in your changes are missing coverage. Please review.

Comparison is base (d7ecd99) 60.0% compared to head (6f441d2) 60.0%.

Additional details and impacted files

Impacted file tree graph

@@                             Coverage Diff                              @@
##             fix/issue-with-intermediate-parents-status   #2271   +/-   ##
============================================================================
  Coverage                                          60.0%   60.0%           
- Complexity                                         4181    4184    +3     
============================================================================
  Files                                               457     457           
  Lines                                             17721   17748   +27     
============================================================================
+ Hits                                              10627   10647   +20     
- Misses                                             7094    7101    +7     
Flag Coverage Δ
php-unit-tests 60.0% <81.1%> (+<0.1%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
src/Jobs/UpdateMerchantProductStatuses.php 92.9% <100.0%> (+0.9%) ⬆️
src/MerchantCenter/MerchantStatuses.php 53.9% <100.0%> (+1.8%) ⬆️
...ers/MerchantCenter/ProductStatisticsController.php 32.4% <0.0%> (-2.3%) ⬇️

@jorgemd24 jorgemd24 changed the title Store merchant status job error Product Statuses - Handle failure of the Update Product Statuses Job Feb 21, 2024
@jorgemd24 jorgemd24 marked this pull request as ready for review February 21, 2024 19:14
Copy link
Member

@ianlin ianlin left a comment

Choose a reason for hiding this comment

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

Thanks for handling failures of update product statuses job. I can see the error in the response data when calling wc/gla/mc/product-statistics endpoint. LGTM.

Base automatically changed from fix/issue-with-intermediate-parents-status to feature/refactor-product-stats February 22, 2024 17:19
@jorgemd24 jorgemd24 merged commit d13c57b into feature/refactor-product-stats Feb 22, 2024
11 checks passed
@jorgemd24 jorgemd24 deleted the add/store-merchant-status-job-error branch February 22, 2024 17:19
@jorgemd24
Copy link
Contributor Author

Thanks @ianlin for your time reviewing this PR!

@eason9487 eason9487 mentioned this pull request Mar 26, 2024
21 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog: add A new feature, function, or functionality was added. type: enhancement The issue is a request for an enhancement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants