add extra check in bg process to recover from errors
This commit is contained in:
parent
2bed781e77
commit
5aa6a65dd6
|
@ -59,9 +59,15 @@ if ( ! class_exists( 'WP_Background_Process' ) ) {
|
|||
|
||||
$this->cron_hook_identifier = $this->identifier . '_cron';
|
||||
$this->cron_interval_identifier = $this->identifier . '_cron_interval';
|
||||
$this->cron_hook_check_identifier = $this->identifier . '_cron_check';
|
||||
|
||||
add_action( $this->cron_hook_identifier, array( $this, 'handle_cron_healthcheck' ) );
|
||||
add_action( $this->cron_hook_check_identifier, array( $this, 'handle_cron_healthcheck_check' ) );
|
||||
add_filter( 'cron_schedules', array( $this, 'schedule_cron_healthcheck' ) );
|
||||
|
||||
if ( ! wp_next_scheduled( $this->cron_hook_check_identifier ) ) {
|
||||
wp_schedule_event( time(), $this->cron_interval_identifier, $this->cron_hook_check_identifier );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -451,6 +457,28 @@ if ( ! class_exists( 'WP_Background_Process' ) ) {
|
|||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks the healthcheck
|
||||
*
|
||||
* If there is an open process, not running, and not scheduled. schedule it.
|
||||
*
|
||||
*/
|
||||
public function handle_cron_healthcheck_check() {
|
||||
if ( $this->is_process_running() ) {
|
||||
// Background process already running.
|
||||
exit;
|
||||
}
|
||||
|
||||
if ( $this->is_queue_empty() ) {
|
||||
// No data to process.
|
||||
$this->clear_scheduled_event();
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->schedule_event();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedule event
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue