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

Make cron schedule configurable #9

Open
wpscholar opened this issue Apr 17, 2023 · 1 comment
Open

Make cron schedule configurable #9

wpscholar opened this issue Apr 17, 2023 · 1 comment

Comments

@wpscholar
Copy link
Member

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.

@wpscholar
Copy link
Member Author

Ultimately, I think we don't have enough classes to represent all the concepts and dependencies that we really want. I think we should probably have the following:

  • Connection - for now, just a DatabaseConnection; handles reading and writing to data source
  • QueryFilter - applied to a connection to allow it to pull only a specific subset of all entries (e.g. tasks by name, or if we change how we do things it could be a Job class name)
  • QueueType (one of Queue, Stack, PriorityQueue) - Handles prioritization of tasks, is essentially an application of a QueryFilter focused primarily on sorting.
  • Schedule - (one of Interval or Event) Handles setting up cron schedules or one-off events. We could have  existing classes that correspond to the pre-existing cron intervals in WordPress (QuarterHourInterval, HourlyInterval, etc)
  • Worker - Takes a connection, schedule, queue type, and (optionally) query filter(s). Handles registration of new tasks, processing tasks, checking task status, recording results, decrementing retries, etc. 
  • Job/Task - Individual unit of work. We should have a standard way of registering these. I like how the wp-queue package does it. Ideally would be extended for each job type.
  • Job/Task Result - Handles storing and fetching of results, mostly standalone, but would rely on a connection type. 

I'm looking at this as inspiration: https://github.com/deliciousbrains/wp-queue

I get that this is a bit of an involved rewrite if we do this, so if we need to circle back to this as a fast follow we can.

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

No branches or pull requests

1 participant