newfold-labs / wp-module-tasks Goto Github PK
View Code? Open in Web Editor NEWA task system for processing asynchronous tasks with wordpress, the tasks could be one-off long running tasks or periodic tasks.
A task system for processing asynchronous tasks with wordpress, the tasks could be one-off long running tasks or periodic tasks.
We should implement some PHPUnit tests for key functionality.
It seems like there would be times when just ordering tasks by priority alone could be limiting. It seems like we might want to have some tasks processed based on date/time, with priority being optional or being an additional sort if priority is the same.
I can see not using priority at all for handling things like processing admin page view events and instead handling those as either a stack (LIFO) or a queue (FIFO).
There could be other times when we would want a true queue or stack instead of a solely priority-based system.
I'd love to see a system where you can instantiate a queue, and configure it to run one or more jobs on a subset of tasks (e.g. by task name) at a specific cron interval. Likewise, you could instantiate a stack or priority queue at different intervals for different subsets of tasks.
I think this package would provide some inspiration in this direction: https://github.com/deliciousbrains/wp-queue
There are some places where $wpdb->prepare()
should be used. It appears this was done in a few places, but is missing in others.
For example: https://github.com/newfold-labs/wp-module-tasks/blob/main/includes/Models/Data/Task.php#L290
Having a 20-second cron schedule could overwhelm the site’s resources with overlapping cron tasks on a high-traffic site.
While I realize this 20-second cron is important when setting up a site to ensure plugins are properly installed during onboarding, I don't think we should retain this cron schedule past onboarding.
wp-module-tasks/includes/Scheduler.php
Lines 36 to 59 in a7d309c
The existing cleanup task should happen on the pre-existing 15-minute cron instead of adding a new 10-minute cron.
We should remove the 20-second cron and make it possible to configure custom cron schedules to handle different groups/types of tasks at different intervals.
Having 9 parameters to instantiate a Task
seems a bit much. Do we really need them all in the constructor?
wp-module-tasks/includes/Models/Data/Task.php
Lines 135 to 143 in a7d309c
For example, why not default to a low or mid-range priority and then allow calling $task->priority( 80 )
to change it?
By introducing chainable methods, we could do something like $task->priority( 80 )->retries(3)
. This allows us to instantiate in a more reader-friendly way and without having to pass null for multiple parameters.
In looking at the code, it seems that there are some things we aren't using at all. To avoid technical debt, it would be best to remove these things.
For example:
Update readme Satis reference:
composer config repositories.newfold composer https://newfold.github.io/satis
Should be:
composer config repositories.newfold composer https://newfold-labs.github.io/satis
We should avoid using // phpcs:ignore
since this ignores ALL rules. I think it is probably irrelevant in most cases since you've addressed the issues. However, if there is a specific rule we are trying to intentionally ignore, we should include the rule name in the comment so that other rules aren't ignored.
Instances:
wp-module-tasks/includes/Models/Data/Task.php
Line 181 in a048966
wp-module-tasks/includes/Models/Data/Task.php
Line 270 in a048966
Line 70 in a048966
Line 72 in a048966
wp-module-tasks/includes/Scheduler.php
Line 101 in a048966
Is there a reason we would disable a task as opposed to just deleting it?
If not, we should remove the enabled
column from the database as well as any class properties, etc.
As a best practice, we should use the set_time_limit()
function instead of the ini_set()
function and setting max_execution_time
.
The primary reason is that the set_time_limit()
function sets the time limit for the current script only. Setting max_execution_time
impacts the entire PHP environment and could cause performance issues.
Currently, table setup checks are being run on every page load. We should change that up so that the plugin can call a function in the module when the plugin is activated (or deactivated) to set up or remove those tables. Alternatively, our plugins have upgrade routines that could handle the table setup.
wp-module-tasks/includes/Models/Data/Task.php
Lines 91 to 117 in a7d309c
wp-module-tasks/includes/Models/Data/TaskResult.php
Lines 12 to 33 in db66d27
Currently, the setup_task_*
functions are still called on every page load. We should move these into a register_activation_hook
call (as you did with the register_deactivation_hook
).
https://github.com/newfold-labs/wp-module-tasks/blob/main/bootstrap.php#L100-L101
Have we looked into adding any additional indexes to our custom tables? Is it worth indexing by task name or priority?
https://spinupwp.com/wordpress-database-optimization-indexing/
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.