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

Release/3.11.0.5 #4958

Merged
merged 3 commits into from
Apr 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion inc/Engine/Common/Queue/AbstractASQueue.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function schedule_single( $timestamp, $hook, $args = [] ) {
* @return string The action ID.
*/
public function schedule_recurring( $timestamp, $interval_in_seconds, $hook, $args = [] ) {
if ( $this->is_scheduled( $hook, $args, $this->group ) ) {
if ( $this->is_scheduled( $hook, $args ) ) {
return '';
}
return as_schedule_recurring_action( $timestamp, $interval_in_seconds, $hook, $args, $this->group );
Expand Down
103 changes: 103 additions & 0 deletions inc/Engine/Common/Queue/Cleaner.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
<?php
declare( strict_types=1 );

namespace WP_Rocket\Engine\Common\Queue;

class Cleaner extends \ActionScheduler_QueueCleaner {

/**
* The duration of clean Hour In seconds.
*
* @var int
*/
protected $hour_in_seconds = 60 * 60;

/**
* Store instance.
*
* @var \ActionScheduler_Store
*/
private $store = null;

/**
* Group name to be cleaned.
*
* @var string
*/
private $group;

/**
* Cleaner constructor.
*
* @param \ActionScheduler_Store|null $store The store instance.
* @param int $batch_size The batch size.
* @param string $group Current queue group.
*/
public function __construct( \ActionScheduler_Store $store = null, $batch_size = 20, $group = '' ) {
parent::__construct( $store, $batch_size );
$this->store = $store ? $store : \ActionScheduler_Store::instance();
$this->group = $group;
}

/**
* Overrides the base method of action scheduler to do the clean process for our actions only.
*
* @return void
*/
public function delete_old_actions() {
$lifespan = (int) apply_filters( 'action_scheduler_retention_period', $this->hour_in_seconds );// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound

/**
* Filters the retention period for our tasks only.
*
* @since 3.11.0.5
*
* @param int $lifespan Lifespan in seconds.
*
* @return int
*/
$lifespan = (int) apply_filters( 'rocket_action_scheduler_retention_period', $lifespan, $this->group );
$cutoff = as_get_datetime_object( $lifespan . ' seconds ago' );

$statuses_to_purge = [
\ActionScheduler_Store::STATUS_COMPLETE,
\ActionScheduler_Store::STATUS_CANCELED,
];

foreach ( $statuses_to_purge as $status ) {
$actions_to_delete = $this->store->query_actions(
[
'status' => $status,
'modified' => $cutoff,
'modified_compare' => '<=',
'per_page' => $this->get_batch_size(),
'orderby' => 'none',
'group' => $this->group,
]
);

foreach ( $actions_to_delete as $action_id ) {
try {
$this->store->delete_action( $action_id );
} catch ( \Exception $e ) {

/**
* Notify 3rd party code of exceptions when deleting a completed action older than the retention period
*
* This hook provides a way for 3rd party code to log or otherwise handle exceptions relating to their
* actions.
*
* @since 2.0.0
*
* @param int $action_id The scheduled actions ID in the data store
* @param \Exception $e The exception thrown when attempting to delete the action from the data store
* @param int $lifespan The retention period, in seconds, for old actions
* @param int $count_of_actions_to_delete The number of old actions being deleted in this batch
*/
do_action( 'action_scheduler_failed_old_action_deletion', $action_id, $e, $lifespan, count( $actions_to_delete ) );// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
}
}
}
}

}
18 changes: 16 additions & 2 deletions inc/Engine/Common/Queue/RUCSSQueueRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,24 @@ public static function instance() {
*
* @param \ActionScheduler_Store|null $store Store Instance.
* @param \ActionScheduler_FatalErrorMonitor|null $monitor Fatal Error monitor instance.
* @param \ActionScheduler_QueueCleaner|null $cleaner Cleaner instance.
* @param Cleaner|null $cleaner Cleaner instance.
* @param \ActionScheduler_AsyncRequest_QueueRunner|null $async_request Async Request Queue Runner instance.
*/
public function __construct( \ActionScheduler_Store $store = null, \ActionScheduler_FatalErrorMonitor $monitor = null, \ActionScheduler_QueueCleaner $cleaner = null, \ActionScheduler_AsyncRequest_QueueRunner $async_request = null ) {
public function __construct( \ActionScheduler_Store $store = null, \ActionScheduler_FatalErrorMonitor $monitor = null, Cleaner $cleaner = null, \ActionScheduler_AsyncRequest_QueueRunner $async_request = null ) {
if ( is_null( $cleaner ) ) {
/**
* Filters the clean batch size.
*
* @since 3.11.0.5
*
* @param int $batch_size Batch size.
*
* @return int
*/
$batch_size = (int) apply_filters( 'rocket_action_scheduler_clean_batch_size', 100, $this->group );
$cleaner = new Cleaner( $store, $batch_size, $this->group );
}

parent::__construct( $store, $monitor, $cleaner );

if ( is_null( $async_request ) ) {
Expand Down
51 changes: 22 additions & 29 deletions inc/Engine/Optimization/RUCSS/Admin/Subscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public static function get_subscribed_events() : array {
],
'wp_ajax_rocket_spawn_cron' => 'spawn_cron',
'rocket_deactivation' => 'cancel_queues',
'shutdown' => 'schedule_rucss_pending_jobs_cron',
'admin_init' => 'schedule_rucss_pending_jobs_cron',
'admin_head-tools_page_action-scheduler' => 'delete_as_tables_transient_on_tools_page',
];
}
Expand Down Expand Up @@ -171,42 +171,35 @@ public function schedule_rucss_pending_jobs_cron() {
return;
}

$error = error_get_last();
try {
if ( ! $this->settings->is_enabled() ) {
if ( ! $this->queue->is_pending_jobs_cron_scheduled() ) {
return;
}

// Delete the transient when any error happens.
if ( null !== $error ) {
delete_transient( 'rocket_rucss_as_tables_count' );
Logger::debug( 'RUCSS: Cancel pending jobs cron job because of disabling RUCSS option.' );

return;
}

if ( ! $this->is_valid_as_tables() ) {
return;
}

if ( ! $this->settings->is_enabled() ) {
if ( ! $this->queue->is_pending_jobs_cron_scheduled() ) {
$this->queue->cancel_pending_jobs_cron();
return;
}

Logger::debug( 'RUCSS: Cancel pending jobs cron job because of disabling RUCSS option.' );

$this->queue->cancel_pending_jobs_cron();
return;
}
/**
* Filters the cron interval.
*
* @since 3.11
*
* @param int $interval Interval in seconds.
*/
$interval = apply_filters( 'rocket_rucss_pending_jobs_cron_interval', 1 * rocket_get_constant( 'MINUTE_IN_SECONDS', 60 ) );

/**
* Filters the cron interval.
*
* @since 3.11
*
* @param int $interval Interval in seconds.
*/
$interval = apply_filters( 'rocket_rucss_pending_jobs_cron_interval', 1 * rocket_get_constant( 'MINUTE_IN_SECONDS', 60 ) );
Logger::debug( "RUCSS: Schedule pending jobs Cron job with interval {$interval} seconds." );

Logger::debug( "RUCSS: Schedule pending jobs Cron job with interval {$interval} seconds." );
$this->queue->schedule_pending_jobs_cron( $interval );
} catch ( \RuntimeException $exception ) {
delete_transient( 'rocket_rucss_as_tables_count' );

$this->queue->schedule_pending_jobs_cron( $interval );
Logger::error( 'RUCSS: Action scheduler ERROR: ' . $exception->getMessage() );
}
}

/**
Expand Down
4 changes: 2 additions & 2 deletions wp-rocket.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: WP Rocket
* Plugin URI: https://wp-rocket.me
* Description: The best WordPress performance plugin.
* Version: 3.11.0.4
* Version: 3.11.0.5
* Requires at least: 5.5
* Requires PHP: 7.1
* Code Name: Iego
Expand All @@ -20,7 +20,7 @@
defined( 'ABSPATH' ) || exit;

// Rocket defines.
define( 'WP_ROCKET_VERSION', '3.11.0.4' );
define( 'WP_ROCKET_VERSION', '3.11.0.5' );
define( 'WP_ROCKET_WP_VERSION', '5.5' );
define( 'WP_ROCKET_WP_VERSION_TESTED', '5.9' );
define( 'WP_ROCKET_PHP_VERSION', '7.1' );
Expand Down