WC_Background_Emailer::handle()
Handle
Description Description
Pass each queue item to the task handler, while remaining within server memory and time limit constraints.
Source Source
File: includes/class-wc-background-emailer.php
protected function handle() {
$this->lock_process();
do {
$batch = $this->get_batch();
if ( empty( $batch->data ) ) {
break;
}
foreach ( $batch->data as $key => $value ) {
$task = $this->task( $value );
if ( false !== $task ) {
$batch->data[ $key ] = $task;
} else {
unset( $batch->data[ $key ] );
}
// Update batch before sending more to prevent duplicate email possibility.
$this->update( $batch->key, $batch->data );
if ( $this->time_exceeded() || $this->memory_exceeded() ) {
// Batch limits reached.
break;
}
}
if ( empty( $batch->data ) ) {
$this->delete( $batch->key );
}
} while ( ! $this->time_exceeded() && ! $this->memory_exceeded() && ! $this->is_queue_empty() );
$this->unlock_process();
// Start next batch or complete process.
if ( ! $this->is_queue_empty() ) {
$this->dispatch();
} else {
$this->complete();
}
}