Skip to content

Commit

Permalink
Use clear scheduled hook to remove package status check
Browse files Browse the repository at this point in the history
The `wp_next_scheduled()` response appears to be subject to caching so for custom cron job intervals such as 1 minute in this case the next scheduled time can be too old for it to ever match the actual next event. This means the current method for clearing the scheduled task fails silently.

Using clear scheduled hook is more appropriate here because it is the arguments that are unique to the task.

Fixes #379
  • Loading branch information
roborourke committed Apr 23, 2021
1 parent 3e347d7 commit 8979ee8
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions inc/elasticsearch_packages/namespace.php
Original file line number Diff line number Diff line change
Expand Up @@ -326,21 +326,15 @@ function on_check_package_status( string $package_id, string $slug, bool $for_ne
}

// Unschedule this status check.
$next = wp_next_scheduled( 'altis.search.check_package_status', $check_status_hook_args );
if ( $next ) {
wp_unschedule_event( $next, 'altis.search.check_package_status', $check_status_hook_args );
}
wp_clear_scheduled_hook( 'altis.search.check_package_status', $check_status_hook_args );

// Schedule the index settings update.
if ( ! wp_next_scheduled( 'altis.search.update_index_settings', $update_index_hook_args ) ) {
wp_schedule_single_event( time() + MINUTE_IN_SECONDS, 'altis.search.update_index_settings', $update_index_hook_args );
}
} catch ( Exception $e ) {
// Unschedule this hook.
$next = wp_next_scheduled( 'altis.search.check_package_status', $check_status_hook_args );
if ( $next ) {
wp_unschedule_event( $next, 'altis.search.check_package_status', $check_status_hook_args );
}
wp_clear_scheduled_hook( 'altis.search.check_package_status', $check_status_hook_args );

// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
trigger_error( $e->getMessage(), E_USER_WARNING );
Expand Down

0 comments on commit 8979ee8

Please sign in to comment.