Giter Site home page Giter Site logo

wp-module-tasks's People

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

wp-module-tasks's Issues

Implement tests

We should implement some PHPUnit tests for key functionality.

Consider making priority optional

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

Make cron schedule configurable

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.

/**
* Add a 20 seconds interval
*
* @param array $schedules The existing interval schedules
*/
public function add_interval_schedule( $schedules ) {
// Adds the schedule for the given intervals in seconds
if ( ! array_key_exists( 'twenty_seconds', $schedules ) || 20 !== $schedules[ 'twenty_seconds' ]['interval'] ) {
$schedules[ 'twenty_seconds' ] = array(
'interval' => 20,
'display' => __( 'Cron to run once every twenty seconds' ),
);
}
// Adds the schedule for the given intervals in seconds
if ( ! array_key_exists( 'ten_minutes', $schedules ) || 600 !== $schedules[ 'ten_minutes' ]['interval'] ) {
$schedules[ 'ten_minutes' ] = array(
'interval' => 600,
'display' => __( 'Cron to run once every ten minutes' ),
);
}
return $schedules;
}

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.

Reconsider method of Task instantiation

Having 9 parameters to instantiate a Task seems a bit much. Do we really need them all in the constructor?

$id = null,
$task_name = null,
$task_executor_path = null,
$task_execute = null,
$args = null,
$num_retries = 0,
$task_interval = null,
$task_priority = null,
$enabled = true

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.

Update Satis reference in readme file

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

Avoid use of `phpcs:ignore`

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:

What are the use cases for disabling a task?

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.

Use `set_time_limit()` instead of `ini_set( 'max_execution_time' )`

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.

Restrict when tables checks are done and add code to allow deleting tables as well

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.

public static function setup() {
global $wpdb;
$table_name = MODULE_TASKS_TASK_TABLE_NAME;
// Maybe create the table
if ( ! function_exists( 'maybe_create_table' ) ) {
require_once ABSPATH . 'wp-admin/includes/upgrade.php';
}
$charset_collate = $wpdb->get_charset_collate();
$sql = "CREATE TABLE `{$wpdb->prefix}{$table_name}` (
task_id bigint(20) NOT NULL AUTO_INCREMENT,
task_name varchar(63) NOT NULL,
task_executor_path varchar(125),
task_execute varchar(125),
args longtext,
num_retries int(2) UNSIGNED,
task_interval int(2) UNSIGNED,
task_priority int(2) UNSIGNED,
task_status varchar(12),
updated TIMESTAMP NOT NULL ON UPDATE CURRENT_TIMESTAMP,
enabled tinyint(1),
PRIMARY KEY (task_id)
) $charset_collate;";
maybe_create_table( $wpdb->prefix . $table_name, $sql );
}

public static function setup() {
global $wpdb;
$table_name = MODULE_TASKS_TASK_RESULTS_TABLE_NAME;
// Maybe create the table
if ( ! function_exists( 'maybe_create_table' ) ) {
require_once ABSPATH . 'wp-admin/includes/upgrade.php';
}
$charset_collate = $wpdb->get_charset_collate();
$sql = "CREATE TABLE `{$wpdb->prefix}{$table_name}` (
task_result_id bigint(20) NOT NULL AUTO_INCREMENT,
task_id bigint(20) NOT NULL,
task_name varchar(63) NOT NULL,
stacktrace longtext,
success tinyint(1),
updated TIMESTAMP NOT NULL ON UPDATE CURRENT_TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (task_result_id)
) $charset_collate;";
maybe_create_table( $wpdb->prefix . $table_name, $sql );
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.