Skip to content

Improve run_cron method #937

Closed
Closed
@poonam279

Description

@poonam279

What problem does this address?

A user on WordPress.org suggested to improve the run cron method in our plugin. He wrote the following message -
I have some issues with the way your plugin is handling what feeds to push to the run_job method of “Feedzy_Rss_Feeds_Import” Your code prevents hook and overwrite of this method ( run_job is private ). So I have a simple modifications to suggest, please consider it.

in the original code from https://plugins.trac.wordpress.org/browser/feedzy-rss-feeds/trunk/includes/admin/feedzy-rss-feeds-import.php

The args used in get_post imply only the first 99 published feeds added can be processed and run_job will probably timeout way before it reach 99 feeds.

in my case i have to edit your plugins in this way

public function run_cron( $max = 10 ) {
[...]
$args = [
    'post_type'   => 'feedzy_imports',
    'post_status' => 'publish',
    'meta_key'    => 'last_run_id',
    'orderby'     => 'meta_value_num',
    'order'       => 'DESC',
    'numberposts' => 10,
];
[...]

i have reduced drastically the limit to never run more than 10 feed for more than 10 article

order on last_run timestamp in order to always run the oldest feed, this way the plugin is way more stable, enable to run cron way more often et do not ignore feeds anymore.

I was enable to run the shreduled task every 15 minutes on more than 300 distinct feeds. and update all of them in the span a a day.

https://wordpress.org/support/topic/run_cron-method-is-terrible/

What is your proposed solution?

He suggests adding a simple hook on the get_post arguments and $max to enable cron behavior editing without plugin editing.

$args = apply_filters( 'feedzy_run_cron_get_posts_args', [
'post_type'   => 'feedzy_imports',
'post_status' => 'publish',
'numberposts' => 99,
] );

Will this feature require documentation? (Optional)

None

Metadata

Metadata

Assignees

Labels

customer reportIndicates the request came from a customer.new featureRequest for a new feature or functionality to be added to the project.

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions