change bg process loop. less interactions with BD

This commit is contained in:
Leo Germani 2018-07-27 16:52:56 -03:00
parent 1e107f8afe
commit 2bed781e77
1 changed files with 21 additions and 19 deletions

View File

@ -254,33 +254,35 @@ abstract class Background_Process extends \WP_Background_Process {
// while we are debugging performance
$newRequest = true;
do {
$batch = $this->get_batch();
$batch = $this->get_batch();
if ($newRequest) {
$this->write_log($batch->key, ['New Request']);
$newRequest = false;
}
// TODO: find a way to catch and log PHP errors as
if ($newRequest) {
$this->write_log($batch->key, ['New Request']);
$newRequest = false;
}
// TODO: find a way to catch and log PHP errors as
$task = $batch;
do {
try {
$task = $this->task( $batch );
$task = $this->task( $task );
} catch (\Exception $e) {
// TODO: Add Stacktrace
$this->write_error_log($batch->key, ['Fatal Error: ' . $e->getMessage()]);
$this->write_error_log($batch->key, ['Process aborted']);
$task = false;
}
} while ( false !== $task && ! $this->time_exceeded() && ! $this->memory_exceeded() );
// Update or close current batch.
if ( false !== $task ) {
$this->update( $batch->key, $task );
} else {
$this->close( $batch->key );
}
} while ( ! $this->time_exceeded() && ! $this->memory_exceeded() && ! $this->is_queue_empty() );
if ( false !== $task ) {
$this->update( $batch->key, $task );
} else {
$this->close( $batch->key );
}
$this->unlock_process();
@ -389,5 +391,5 @@ abstract class Background_Process extends \WP_Background_Process {
return $return;
}
}