← All changes
|
modules/optimization/components/single-optimization.php
+16
-11
1.5.4
→
1.7.7
View file →
| @@ -11,8 +11,9 @@ | ||
| 11 | 11 | Image_Status |
| 12 | 12 | }; |
| 13 | 13 | use ImageOptimization\Classes\Logger; |
| 14 | 14 | use ImageOptimization\Classes\Exceptions\Quota_Exceeded_Error; |
| 15 | +use ImageOptimization\Modules\Connect\Classes\Exceptions\Connection_Error; | |
| 15 | 16 | use ImageOptimization\Modules\Optimization\Classes\Exceptions\Image_File_Already_Exists_Error; |
| 16 | 17 | use ImageOptimization\Modules\Optimization\Classes\Optimize_Image; |
| 17 | 18 | use Throwable; |
| 18 | 19 | |
| @@ -34,8 +35,13 @@ | ||
| 34 | 35 | ( new Image_Meta( $image_id ) ) |
| 35 | 36 | ->set_status( Image_Status::OPTIMIZATION_FAILED ) |
| 36 | 37 | ->set_error_type( Image_Optimization_Error_Type::QUOTA_EXCEEDED ) |
| 37 | 38 | ->save(); |
| 39 | + } catch ( Connection_Error $ce ) { | |
| 40 | + ( new Image_Meta( $image_id ) ) | |
| 41 | + ->set_status( Image_Status::OPTIMIZATION_FAILED ) | |
| 42 | + ->set_error_type( Image_Optimization_Error_Type::CONNECTION_ERROR ) | |
| 43 | + ->save(); | |
| 38 | 44 | } catch ( Image_File_Already_Exists_Error $fe ) { |
| 39 | 45 | ( new Image_Meta( $image_id ) ) |
| 40 | 46 | ->set_status( Image_Status::OPTIMIZATION_FAILED ) |
| 41 | 47 | ->set_error_type( Image_Optimization_Error_Type::FILE_ALREADY_EXISTS ) |
| @@ -40,14 +46,11 @@ | ||
| 40 | 46 | ->set_status( Image_Status::OPTIMIZATION_FAILED ) |
| 41 | 47 | ->set_error_type( Image_Optimization_Error_Type::FILE_ALREADY_EXISTS ) |
| 42 | 48 | ->save(); |
| 43 | 49 | } catch ( Throwable $t ) { |
| 44 | - Logger::log( Logger::LEVEL_ERROR, 'Optimization error. Reason: ' . $t->getMessage() ); | |
| 50 | + Logger::error( 'Single optimization error. Reason: ' . $t->getMessage() ); | |
| 45 | 51 | |
| 46 | - ( new Image_Meta( $image_id ) ) | |
| 47 | - ->set_status( Image_Status::OPTIMIZATION_FAILED ) | |
| 48 | - ->set_error_type( Image_Optimization_Error_Type::GENERIC ) | |
| 49 | - ->save(); | |
| 52 | + Retry::maybe_retry_optimization( $image_id ); | |
| 50 | 53 | } |
| 51 | 54 | } |
| 52 | 55 | |
| 53 | 56 | /** @async */ |
| @@ -71,8 +74,13 @@ | ||
| 71 | 74 | ( new Image_Meta( $image_id ) ) |
| 72 | 75 | ->set_status( Image_Status::REOPTIMIZING_FAILED ) |
| 73 | 76 | ->set_error_type( Image_Optimization_Error_Type::QUOTA_EXCEEDED ) |
| 74 | 77 | ->save(); |
| 78 | + } catch ( Connection_Error $ce ) { | |
| 79 | + ( new Image_Meta( $image_id ) ) | |
| 80 | + ->set_status( Image_Status::OPTIMIZATION_FAILED ) | |
| 81 | + ->set_error_type( Image_Optimization_Error_Type::CONNECTION_ERROR ) | |
| 82 | + ->save(); | |
| 75 | 83 | } catch ( Image_File_Already_Exists_Error $fe ) { |
| 76 | 84 | ( new Image_Meta( $image_id ) ) |
| 77 | 85 | ->set_status( Image_Status::REOPTIMIZING_FAILED ) |
| 78 | 86 | ->set_error_type( Image_Optimization_Error_Type::FILE_ALREADY_EXISTS ) |
| @@ -77,18 +85,15 @@ | ||
| 77 | 85 | ->set_status( Image_Status::REOPTIMIZING_FAILED ) |
| 78 | 86 | ->set_error_type( Image_Optimization_Error_Type::FILE_ALREADY_EXISTS ) |
| 79 | 87 | ->save(); |
| 80 | 88 | } catch ( Throwable $t ) { |
| 81 | - Logger::log( Logger::LEVEL_ERROR, 'Reoptimizing error. Reason: ' . $t->getMessage() ); | |
| 89 | + Logger::error( 'Single reoptimizing error. Reason: ' . $t->getMessage() ); | |
| 82 | 90 | |
| 83 | - ( new Image_Meta( $image_id ) ) | |
| 84 | - ->set_status( Image_Status::REOPTIMIZING_FAILED ) | |
| 85 | - ->set_error_type( Image_Optimization_Error_Type::GENERIC ) | |
| 86 | - ->save(); | |
| 91 | + Retry::maybe_retry_optimization( $image_id ); | |
| 87 | 92 | } |
| 88 | 93 | } |
| 89 | 94 | |
| 90 | 95 | public function __construct() { |
| 91 | - add_action( Async_Operation_Hook::OPTIMIZE_SINGLE, [ $this, 'optimize_single_image' ] ); | |
| 96 | + add_action( Async_Operation_Hook::OPTIMIZE_SINGLE, [ $this, 'optimize_single_image' ], 3 ); | |
| 92 | 97 | add_action( Async_Operation_Hook::REOPTIMIZE_SINGLE, [ $this, 'reoptimize_single_image' ] ); |
| 93 | 98 | } |
| 94 | 99 | } |