Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:wp-media/wp-rocket into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
wordpressfan committed Nov 3, 2023
2 parents 7c33726 + fdd1be6 commit c80722e
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 106 deletions.
3 changes: 1 addition & 2 deletions inc/Engine/Optimization/RUCSS/Controller/UsedCSS.php
Original file line number Diff line number Diff line change
Expand Up @@ -580,8 +580,7 @@ public function check_job_status( int $id ) {
}

// Increment the retries number with 1 , Change status to pending again and change job id on timeout.
$this->used_css_query->increment_retries( $id, (int) $row_details->retries );
$this->used_css_query->update_message( $id, (int) $job_details['code'], $job_details['message'], $row_details->error_message );
$this->used_css_query->increment_retries( $id, (int) $job_details['code'], $job_details['message'] );

// @Todo: Maybe we can add this row to the async job to get the status before the next cron

Expand Down
48 changes: 23 additions & 25 deletions inc/Engine/Optimization/RUCSS/Database/Queries/UsedCSS.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,20 +162,33 @@ public function get_on_submit_jobs( int $count = 100 ) {
/**
* Increment retries number and change status back to pending.
*
* @param int $id DB row ID.
* @param int $retries Current number of retries.
* @param int $id DB row ID.
* @param int $error_code error code.
* @param string $error_message error message.
*
* @return bool
*/
public function increment_retries( $id, $retries = 0 ) {
public function increment_retries( $id, int $error_code, string $error_message ) {
if ( ! self::$table_exists && ! $this->table_exists() ) {
return false;
}

$old = $this->get_item( $id );

$retries = 0;
$previous_message = '';

if ( $old ) {
$retries = $old->retries;
$previous_message = $old->error_message;
}

$update_data = [
'retries' => $retries + 1,
'status' => 'pending',
'retries' => $retries + 1,
'status' => 'pending',
'error_message' => $previous_message . ' - ' . current_time( 'mysql', true ) . " {$error_code}: {$error_message}",
];

return $this->update_item( $id, $update_data );
}

Expand Down Expand Up @@ -284,12 +297,16 @@ public function make_status_failed( int $id, string $error_code, string $error_m
return false;
}

$old = $this->get_item( $id );

$previous_message = $old ? $old->error_message : '';

return $this->update_item(
$id,
[
'status' => 'failed',
'error_code' => $error_code,
'error_message' => current_time( 'mysql', true ) . " {$error_code}: {$error_message}",
'error_message' => $previous_message . ' - ' . current_time( 'mysql', true ) . " {$error_code}: {$error_message}",
]
);
}
Expand Down Expand Up @@ -561,25 +578,6 @@ private function table_exists(): bool {
return $exists;
}

/**
* Update the error message.
*
* @param int $job_id Job ID.
* @param int $code Response code.
* @param string $message Response message.
* @param string $previous_message Previous saved message.
*
* @return bool
*/
public function update_message( int $job_id, int $code, string $message, string $previous_message = '' ): bool {
return $this->update_item(
$job_id,
[
'error_message' => $previous_message . ' - ' . current_time( 'mysql', true ) . " {$code}: {$message}",
]
);
}

/**
* Change the status to be pending.
*
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,7 @@ public function testShouldReturnAsExpected( $config, $expected ) {
}
$this->usedCssQuery->expects( self::once() )
->method( 'increment_retries' )
->with( $config['job_id'], $row_details->retries );

$this->usedCssQuery->expects(self::once())
->method('update_message')
->with($config['job_id'], $job_details['code'], $job_details['message']);
->with( $config['job_id'], $job_details['code'], $job_details['message'] );

$this->usedCss->check_job_status( $config['job_id'] );

Expand Down

This file was deleted.

0 comments on commit c80722e

Please sign in to comment.