wip: broadcast

This commit is contained in:
Andras Bacsai
2023-12-04 20:47:32 +01:00
parent 17deff4d86
commit 42ee4ca032
22 changed files with 142 additions and 103 deletions

View File

@@ -1,6 +1,6 @@
<?php
namespace App\Providers;
namespace App\Events;
use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\InteractsWithSockets;
@@ -14,14 +14,25 @@ class ApplicationDeploymentFinished implements ShouldBroadcast
{
use Dispatchable, InteractsWithSockets, SerializesModels;
public function __construct()
public ?int $teamId = null;
/**
* Create a new event instance.
*/
public function __construct(public ?string $applicationUuid = null, public ?string $status = null)
{
$this->teamId = auth()->user()->currentTeam()->id;
}
/**
* Get the channels the event should broadcast on.
*
* @return array<int, \Illuminate\Broadcasting\Channel>
*/
public function broadcastOn(): array
{
return [
new Channel('custom-channel'),
new PrivateChannel("custom.{$this->teamId}"),
];
}
}

View File

@@ -10,7 +10,6 @@ class Dashboard extends Component
{
public $projects = [];
public $servers = [];
public function mount()
{
$this->servers = Server::ownedByCurrentTeam()->get();

View File

@@ -26,7 +26,7 @@ class Configuration extends Component
return redirect()->route('dashboard');
}
$this->application = $application;
$mainServer = $application->destination->server;
$mainServer = $this->application->destination->server;
$servers = Server::ownedByCurrentTeam()->get();
$this->servers = $servers->filter(function ($server) use ($mainServer) {
return $server->id != $mainServer->id;

View File

@@ -17,11 +17,7 @@ class DeploymentNavbar extends Component
public Application $application;
public Server $server;
public bool $is_debug_enabled = false;
protected $listeners = ['deploymentFinished','echo:custom-channel,ApplicationDeploymentFinished' => 'notifyNewOrder'];
public function notifyNewOrder() {
ray('New order received');
}
protected $listeners = ['deploymentFinished'];
public function mount()
{
$this->application = Application::find($this->application_deployment_queue->application_id);

View File

@@ -11,11 +11,24 @@ use Visus\Cuid2\Cuid2;
class Heading extends Component
{
protected string $deploymentUuid;
public Application $application;
public array $parameters;
public function getListeners()
{
$teamId = auth()->user()->currentTeam()->id;
return [
"echo-private:custom.{$teamId},ApplicationDeploymentFinished" => 'updateStatus',
];
}
protected string $deploymentUuid;
public function updateStatus($message)
{
$applicationUuid = data_get($message, 'applicationUuid');
if ($this->application->uuid === $applicationUuid) {
$this->application->status = data_get($message, 'status');
}
}
public function mount()
{
$this->parameters = get_route_parameters();

View File

@@ -44,6 +44,7 @@ class Form extends Component
{
$this->wildcard_domain = $this->server->settings->wildcard_domain;
$this->cleanup_after_percentage = $this->server->settings->cleanup_after_percentage;
$this->validateServer();
}
public function serverRefresh($install = true)
{

View File

@@ -4,6 +4,7 @@ namespace App\Jobs;
use App\Enums\ApplicationDeploymentStatus;
use App\Enums\ProxyTypes;
use App\Events\ApplicationDeploymentFinished;
use App\Models\Application;
use App\Models\ApplicationDeploymentQueue;
use App\Models\ApplicationPreview;
@@ -14,7 +15,6 @@ use App\Models\StandaloneDocker;
use App\Models\SwarmDocker;
use App\Notifications\Application\DeploymentFailed;
use App\Notifications\Application\DeploymentSuccess;
use App\Providers\ApplicationDeploymentFinished;
use App\Traits\ExecuteRemoteCommand;
use Exception;
use Illuminate\Bus\Queueable;
@@ -102,7 +102,7 @@ class ApplicationDeploymentNewJob implements ShouldQueue, ShouldBeEncrypted
});
}
$this->next(ApplicationDeploymentStatus::FINISHED->value);
ApplicationDeploymentFinished::dispatch($this->application, $this->deployment);
ApplicationDeploymentFinished::dispatch($this->application->uuid, ApplicationDeploymentStatus::FINISHED->value);
} catch (Throwable $exception) {
$this->fail($exception);
} finally {

View File

@@ -382,17 +382,17 @@ class Server extends BaseModel
public function validateConnection()
{
$server = Server::find($this->id);
if ($this->skipServer()) {
if ($server->skipServer()) {
return false;
}
$uptime = instant_remote_process(['uptime'], $this, false);
$uptime = instant_remote_process(['uptime'], $server, false);
if (!$uptime) {
$this->settings()->update([
$server->settings()->update([
'is_reachable' => false,
]);
return false;
} else {
$this->settings()->update([
$server->settings()->update([
'is_reachable' => true,
]);
$server->update([
@@ -400,8 +400,8 @@ class Server extends BaseModel
]);
}
if (data_get($this, 'unreachable_notification_sent') === true) {
$this->team->notify(new Revived($this));
if (data_get($server, 'unreachable_notification_sent') === true) {
$server->team->notify(new Revived($server));
$server->update(['unreachable_notification_sent' => false]);
}

View File

@@ -8,31 +8,15 @@ use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvi
class EventServiceProvider extends ServiceProvider
{
/**
* The event to listener mappings for the application.
*
* @var array<class-string, array<int, class-string>>
*/
protected $listen = [
// Registered::class => [
// SendEmailVerificationNotification::class,
// ],
ApplicationDeploymentFinished::class => [
SendDeploymentNotification::class,
],
];
/**
* Register any events for your application.
*/
public function boot(): void
{
//
}
/**
* Determine if events and listeners should be automatically discovered.
*/
public function shouldDiscoverEvents(): bool
{
return false;

View File

@@ -1,28 +0,0 @@
<?php
namespace App\Providers;
use App\Providers\ApplicationDeploymentFinished;
use Illuminate\Contracts\Events\ShouldHandleEventsAfterCommit;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
class SendDeploymentNotification implements ShouldQueue, ShouldHandleEventsAfterCommit
{
use InteractsWithQueue;
/**
* Create the event listener.
*/
public function __construct()
{
//
}
/**
* Handle the event.
*/
public function handle(ApplicationDeploymentFinished $event): void
{
ray('SendDeploymentNotification');
}
}