Skip to content

Commit fd5de27

Browse files
Add signal handling integration for site cleanup
- Register cleanup handler with Terminus core when site is created - Fix broken cleanup() method call to use cleanupPantheonSite() - Add debug logging for cleanup handler registration and execution - Ensure sites are properly cleaned up when interrupted by SIGINT/SIGTERM Depends on: pantheon-systems/terminus#2731 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 30fc6c6 commit fd5de27

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/Commands/Site/CreateCommand.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,18 @@ protected function createExternallyHostedSite($site_name, $label, Upstream $upst
454454
}
455455
$this->log()->notice('Pantheon site record created successfully (ID: {id}).', ['id' => $site_uuid]);
456456

457+
// Register cleanup handler for signal handling
458+
if ($terminus = \Pantheon\Terminus\Terminus::getInstance()) {
459+
$this->log()->debug('Registering cleanup handler for site: {site_uuid}', ['site_uuid' => $site_uuid]);
460+
$terminus->registerCleanupHandler(function () use ($site_uuid) {
461+
$this->log()->notice('Cleanup handler called for site: {site_uuid}', ['site_uuid' => $site_uuid]);
462+
$this->cleanupPantheonSite($site_uuid, 'Interrupted by signal');
463+
});
464+
$this->log()->debug('Cleanup handler registered successfully for site: {site_uuid}', ['site_uuid' => $site_uuid]);
465+
} else {
466+
$this->log()->error('Could not get Terminus instance to register cleanup handler');
467+
}
468+
457469
// 4. Interact with go-vcs-service: Create Workflow
458470
$this->log()->notice('Initiating workflow with VCS service...');
459471
$vcs_workflow_data = [
@@ -495,7 +507,7 @@ protected function createExternallyHostedSite($site_name, $label, Upstream $upst
495507
$this->log()->debug('VCS auth URL: {url}', ['url' => $auth_url]);
496508
// GitHub requires an authorization URL.
497509
if ($vcs_provider === 'github' && (is_null($auth_url) || $auth_url === '""')) {
498-
$this->cleanup($site_uuid);
510+
$this->cleanupPantheonSite($site_uuid, 'No vcs_auth_link returned');
499511
throw new TerminusException(
500512
'Error authorizing with vcs service: {error_message}',
501513
['error_message' => 'No vcs_auth_link returned']
@@ -933,6 +945,7 @@ private function getPreferredPlatformForFramework($site_type): string
933945
*/
934946
protected function cleanupPantheonSite(string $site_uuid, string $failure_reason, bool $cleanup_vcs = true): void
935947
{
948+
$this->log()->debug('cleanupPantheonSite called with site_uuid: {site_uuid}, reason: {reason}', ['site_uuid' => $site_uuid, 'reason' => $failure_reason]);
936949
$this->log()->error('Site creation failed: {reason}', ['reason' => $failure_reason]);
937950
$this->log()->notice("Attempting to clean up Pantheon site (ID: {id})...", ['id' => $site_uuid]);
938951

0 commit comments

Comments
 (0)