Skip to content

Commit

Permalink
Bugfix: Remove last error check (PR #4941)
Browse files Browse the repository at this point in the history
* remove last error check
* use try catch to detect any runtime error (deleted AS tables)
  • Loading branch information
engahmeds3ed committed Apr 21, 2022
1 parent 1d35d6a commit e219e90
Showing 1 changed file with 22 additions and 29 deletions.
51 changes: 22 additions & 29 deletions inc/Engine/Optimization/RUCSS/Admin/Subscriber.php
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

0 comments on commit e219e90

Please sign in to comment.