This repository has been archived by the owner on Sep 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ability to have a pool of pre-generated PHP environments (#191)
* Add table forzpare sites * Log new site into spare_sites table * Log app id in spare_sites * Check if there is an available spare_site * Do not depend on SP API response data structure. Just use flat array for representing a PHP app * Do not depend on SP API response data structure. Just use flat array for representing a system user * Make default PHP version be a setting * Add Command Line Interface * Allow to launch a spare site from cli * Add get_sp_app and update_sp_app * Make it launch first php app and install WordPress ourselves * Drop action interface for filterable class name interface for provisioning-specific stuff * Log user who launched a site * Note if site was launched via cli * Add ability to launch sites taking them from a pool of spare sites * Add purge command to cli * Move name generation collision mitigation logic to generate_random_subdomain() * Do not wait for ssl forcing action * Add ability to populate pool of spare sites * Fix case when we do not need to launch more spare sites * Decouple SSL certificate addition and SSL forced redirection * Add settinig for disabling spare sites * Show user that launched the site * Always register wildcard for sites - Previously wildcard subdomain was only available for subdomain based multisite * Update debug function to format objects and array * Just launch one spare site at a time when refreshing the pool * Delete record of a spare site if the app does not exist anymore * Avoid race conditions when picking a spare site * Add setting to disable launching if no spare site available * Bump version to 5.0
- Loading branch information
Showing
8 changed files
with
732 additions
and
429 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php | ||
|
||
namespace jn; | ||
|
||
if ( ! defined( '\\ABSPATH' ) ) { | ||
exit; | ||
} | ||
|
||
/** | ||
* Comand Line Interface to Jurassic Ninja's deeds. | ||
*/ | ||
class JN_CLI_Command extends \WP_CLI_Command { | ||
/** | ||
* Launch a spare site. | ||
*/ | ||
public function launch( $args ) { | ||
if ( count( $args ) ) { | ||
if ( $args[0] === 'spare' ) { | ||
\WP_CLI::line( 'Launching a spare site' ); | ||
} | ||
$app = launch_wordpress( 'default', [], true ); | ||
\WP_CLI::line( sprintf( 'Launched spare site', $app->domains[0] ) ); | ||
return; | ||
} | ||
try { | ||
$app = launch_wordpress( 'default', [ 'ssl' => true ] ); | ||
if ( !$app ) { | ||
throw new \Exception(); | ||
} | ||
\WP_CLI::line( sprintf( 'Launched %s', $app->domains[0] ) ); | ||
|
||
} catch ( \Exception $e ) { | ||
\WP_CLI::line( sprintf( 'Error launching site' ) ); | ||
} | ||
} | ||
|
||
/** | ||
* Run the purge job. | ||
*/ | ||
public function purge( $args ) { | ||
try { | ||
$purged = purge_sites(); | ||
if ( is_array( $purged ) && count( $purged ) ) { | ||
\WP_CLI::line( sprintf( 'Purged %s Jurassic Ninja site(s).', count( $purged ) ) ); | ||
} else { | ||
\WP_CLI::line( sprintf( "There weren't any sites to purge" ) ); | ||
} | ||
|
||
} catch ( \Exception $e ) { | ||
\WP_CLI::line( sprintf( 'Error purging Jurassic Ninja sites' ) ); | ||
} | ||
} | ||
|
||
/** | ||
* Refresh the spare sites pooll. | ||
*/ | ||
public function pool( $args ) { | ||
try { | ||
maintain_spare_sites_pool(); | ||
\WP_CLI::line( sprintf( "Spare sites pool was refreshed" ) ); | ||
} catch ( \Exception $e ) { | ||
\WP_CLI::line( sprintf( 'Error refreshing the spare sites pool' ) ); | ||
} | ||
} | ||
} | ||
|
||
\WP_CLI::add_command( 'jn', 'jn\JN_CLI_Command' ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.