Skip to content

Fix Task Scheduler Teardown & Improve Scheduler Creation #132

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/Commands/TearDownCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.'));
Expand Down
2 changes: 2 additions & 0 deletions app/Services/Forge/Pipeline/DestroySite.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ class DestroySite

public function __invoke(ForgeService $service, Closure $next)
{
$this->information('Processing site deletion.');

$service->site->delete();

return $next($service);
Expand Down
6 changes: 3 additions & 3 deletions app/Services/Forge/Pipeline/EnsureJobScheduled.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
}
}
39 changes: 39 additions & 0 deletions app/Services/Forge/Pipeline/RemoveTaskScheduler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

declare(strict_types=1);

/**
* This file is part of Laravel Harbor.
*
* (c) Mehran Rasulian <mehran.rasulian@gmail.com>
*
* 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);
}
}
Loading