diff --git a/app/Commands/TearDownCommand.php b/app/Commands/TearDownCommand.php index 083bda6..71333a9 100644 --- a/app/Commands/TearDownCommand.php +++ b/app/Commands/TearDownCommand.php @@ -21,6 +21,7 @@ use App\Services\Forge\Pipeline\RemoveDatabaseUser; use App\Services\Forge\Pipeline\RemoveExistingDeployKey; use App\Services\Forge\Pipeline\RemoveInertiaSupport; +use App\Services\Forge\Pipeline\RemoveTaskScheduler; use App\Services\Forge\Pipeline\RunOptionalCommands; use App\Traits\Outputifier; use Illuminate\Support\Facades\Pipeline; @@ -45,6 +46,7 @@ public function handle(ForgeService $service): void RemoveDatabaseUser::class, RemoveExistingDeployKey::class, RemoveDaemons::class, + RemoveTaskScheduler::class, DestroySite::class, ]) ->then(fn () => $this->success('Environment teardown successful! All provisioned resources have been removed.')); diff --git a/app/Services/Forge/Pipeline/DestroySite.php b/app/Services/Forge/Pipeline/DestroySite.php index 66ff1a1..3e85828 100644 --- a/app/Services/Forge/Pipeline/DestroySite.php +++ b/app/Services/Forge/Pipeline/DestroySite.php @@ -23,6 +23,8 @@ class DestroySite public function __invoke(ForgeService $service, Closure $next) { + $this->information('Processing site deletion.'); + $service->site->delete(); return $next($service); diff --git a/app/Services/Forge/Pipeline/EnsureJobScheduled.php b/app/Services/Forge/Pipeline/EnsureJobScheduled.php index 2cc40d2..387a968 100644 --- a/app/Services/Forge/Pipeline/EnsureJobScheduled.php +++ b/app/Services/Forge/Pipeline/EnsureJobScheduled.php @@ -32,7 +32,7 @@ public function __invoke(ForgeService $service, Closure $next) private function setupJobIfRequired(ForgeService $service): void { - $command = $this->buildScheduledJobCommand($service->site->name); + $command = $this->buildScheduledJobCommand($service->site->username, $service->site->name); foreach ($service->forge->jobs($service->server->id) as $job) { if ($job->command === $command) { @@ -50,8 +50,8 @@ private function setupJobIfRequired(ForgeService $service): void ]); } - protected function buildScheduledJobCommand(string $domain): string + protected function buildScheduledJobCommand(string $username, string $domain): string { - return sprintf('php /home/forge/%s/artisan schedule:run', $domain); + return sprintf('php /home/%s/%s/artisan schedule:run', $username, $domain); } } diff --git a/app/Services/Forge/Pipeline/RemoveTaskScheduler.php b/app/Services/Forge/Pipeline/RemoveTaskScheduler.php new file mode 100644 index 0000000..adfc325 --- /dev/null +++ b/app/Services/Forge/Pipeline/RemoveTaskScheduler.php @@ -0,0 +1,39 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace App\Services\Forge\Pipeline; + +use App\Services\Forge\ForgeService; +use App\Traits\Outputifier; +use Closure; + +class RemoveTaskScheduler +{ + use Outputifier; + + public function __invoke(ForgeService $service, Closure $next) + { + foreach ($service->forge->jobs($service->setting->server) as $job) { + if ($job->command === sprintf('php /home/%s/%s/artisan schedule:run', $service->site->username, $service->site->name)) { + $this->information('Removing scheduled command.'); + + $job->delete(); + } + } + + // Wait a few seconds to make sure the scheduler is fully removed before kicking off the next task + sleep(10); + + return $next($service); + } +}