Skip to content

Commit a0c9000

Browse files
committed
Log exceptions when creating CloudFront invalidations.
1 parent 416ebba commit a0c9000

1 file changed

Lines changed: 11 additions & 18 deletions

File tree

src/Deployer.php

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Aws\CloudFront\CloudFrontClient;
99
use Aws\Exception\AwsException;
1010
use Aws\Credentials\Credentials;
11+
use WP2Static\WsLog;
1112

1213
class Deployer {
1314

@@ -173,11 +174,12 @@ public function upload_files( string $processed_site_path ) : void {
173174
$num_stale = count( $cf_stale_paths );
174175
if ( $distribution_id && $num_stale > 0 ) {
175176
if ( $num_stale > $cf_max_paths ) {
176-
self::cloudfront_invalidate_all_items();
177+
WsLog::l( 'Invalidating all CloudFront paths' );
178+
self::invalidate_items( $distribution_id, [ '/*' ] );
177179
} else {
178180
$path_text = ( $num_stale === 1 ) ? 'path' : 'paths';
179-
\WP2Static\WsLog::l( "Invalidating $num_stale CloudFront $path_text" );
180-
self::create_invalidation( $distribution_id, $cf_stale_paths );
181+
WsLog::l( "Invalidating $num_stale CloudFront $path_text" );
182+
self::invalidate_items( $distribution_id, $cf_stale_paths );
181183
}
182184
}
183185
}
@@ -285,22 +287,13 @@ public static function create_invalidation( string $distribution_id, array $item
285287
);
286288
}
287289

288-
public static function cloudfront_invalidate_all_items() : void {
289-
if ( ! Controller::getValue( 'cfDistributionID' ) ) {
290-
return;
291-
}
292-
293-
\WP2Static\WsLog::l( 'Invalidating all CloudFront paths' );
294-
290+
public static function invalidate_items( string $distribution_id, array $items ) : ?string {
295291
try {
296-
self::create_invalidation(
297-
Controller::getValue( 'cfDistributionID' ),
298-
[ '/*' ]
299-
);
300-
} catch ( AwsException $e ) {
301-
// output error message if fails
302-
error_log( $e->getMessage() );
292+
return self::create_invalidation( $distribution_id, $items );
293+
} catch (AwsException $e) {
294+
WsLog::l( 'Error creating CloudFront invalidation: ' . $e->getMessage() );
295+
return null;
303296
}
304297
}
305-
}
306298

299+
}

0 commit comments

Comments
 (0)