Comments (7)
Scope a solution
To solve this issue, we are planning to overhaul the retry system, and it could be interesting to consider adopting a Strategy design pattern approach to achieve this. Here's the proposed plan:
-
Strategy Design Pattern: We'll utilize the Strategy design pattern, which you can learn more about here. This pattern allows us to define various strategies for handling different API responses.
-
Namespace Organization: All the code related to these strategies will be placed within a dedicated Strategy namespace for better organization.
-
Interface Definition: An interface will be created to establish the contract for all these strategies. This interface serves as a blueprint for all future strategy implementations.
-
Strategy Classes: We will develop multiple classes, each implementing the interface, to represent different strategies for handling API responses. These classes will define what actions to take based on the API result. Which means we will be able to a different strategy depending on the
job_result
from the API. -
Controller Integration: Within our application's controller (the "RUCSS Controller"), we will integrate these strategy classes to make decisions on how to handle the API response. Depending on the result received from the API, we will choose the appropriate strategy to execute.
-
Future-Proofing: By adopting the Strategy pattern, we are making our system flexible and ready for future changes. It will be easy to add new strategies or modify existing ones as needed without major code alterations.
While Mathieu says:
In case the job has been found but with no results, the plugin must retry for longer than 3 minutes after the job has been sent. This timing must be filterable, but a good target would be up to 30 minutes.
In case the job has not been found on the SaaS, the plugin must retry once, but not more.
In case of 408, creating a new job must also reset the retry strategy.
We can see here different strategies that will have to be implemented.
For point 2, the ideal approach would be an exponential backoff: Try after 1 minute, then 2 minutes, then 5, then 10, then 10 for instance. Another quick&dirty approach could be to increase the number of retries. Both should be groomed to decide.
I think it would be nice to go with the exponential approach. For this, we can create a new column in the database called not_proceed_before
which would be a timestamp.
Then in the strategy, we could check the column
retries to get the information to which level we are, and calculate a timestamp stored in not_proceed_before
.
Then in the function that process the in-progress jobs here, we can add a check to make sure the not_proceed_before
timestamp of the pending job is < now()
.
Development steps:
- [] Implement the Strategy Interface,
- [] Implement the Strategies
- [] Use strategies within the RUCSS Controller
Effort estimation:
M
Is a refactor needed in that part of the codebase?
Yes, as explain in the solution
from wp-rocket.
@CrochetFeve0251 , I would say a S for me, but an XS for you and probably others :)
from wp-rocket.
@Miraeld could you provide an estimation of the effort for the exponential waiting time?
from wp-rocket.
I would like to complete the grooming: to switch between different strategies we gonna use a StrategyFactory
which gonna take in parameter the response from the API and which return the right strategy based on it.
We could then set the strategy on the context.
Otherwise that seems good to me.
from wp-rocket.
Error code refinement discussed here: https://wp-media.slack.com/archives/CUT7FLHF1/p1698749275154029
from wp-rocket.
I updated the ticket based on the Slack discussion, and added Acceptance Criteria as well to better frame the behavior.
from wp-rocket.
Another quick update to simplify the 404 and 422 behavior (fail immediately).
I documented a recap of the expected behavior on Notion: https://www.notion.so/wpmedia/TDD-RUCSS-SaaS-f69dfa7c2a9f4687a7fe7c2b3920aaa0?pvs=4#b50c86a037754405b5c18ed58704832c
from wp-rocket.
Related Issues (20)
- Make WP Rocket pass the new WordPress Plugin Check and automate it in the CI
- Copy changes in `Remove Unused CSS` HOT 1
- Reduce number of fonts loaded HOT 1
- 3.17 - Refactor Activation process
- 3.17 - Refactor Admin
- 3.17 - Refactor WarmUp
- 3.17 - Refactor ServiceProvider HOT 1
- 3.17 - Refactor AJAX Process
- 3.17 Sub tasks - Factories Creation
- 3.17 Sub tasks - Frontend Refactoring
- 3.17 Sub tasks - Database Refactoring HOT 1
- 3.17 - Beacon Script Implementation
- 3.17 - Refactor Cron
- Exclude the regular image when a nextgen is detected on OCI HOT 2
- WP - Rocket / Cloudflare Turnstile / Elementor PopUp
- WP Rocket delay JS and Sentry integration compatibility.
- Clear Critical Images on site logo change on pages using it as LCP
- Increase PHPStan level to 3
- Update CRON Notice in Admin
- Update "can't create rucss_used_css table" admin notice
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from wp-rocket.