mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-06 00:12:35 +00:00
Migrate queues to Horizon (#621)
This commit is contained in:
@ -65,7 +65,7 @@ public function delete(Backup $backup): void
|
||||
}
|
||||
|
||||
$backup->delete();
|
||||
});
|
||||
})->onQueue('ssh');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -30,6 +30,6 @@ public function delete(BackupFile $file): void
|
||||
|
||||
dispatch(function () use ($file): void {
|
||||
$file->deleteFile();
|
||||
});
|
||||
})->onQueue('ssh');
|
||||
}
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ public function restore(BackupFile $backupFile, array $input): void
|
||||
})->catch(function () use ($backupFile): void {
|
||||
$backupFile->status = BackupFileStatus::RESTORE_FAILED;
|
||||
$backupFile->save();
|
||||
})->onConnection('ssh');
|
||||
})->onQueue('ssh');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -39,7 +39,7 @@ public function run(Backup $backup): BackupFile
|
||||
$backup->save();
|
||||
$file->status = BackupFileStatus::FAILED;
|
||||
$file->save();
|
||||
})->onConnection('ssh');
|
||||
})->onQueue('ssh');
|
||||
|
||||
return $file;
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ public function create(Server $server, array $input): FirewallRule
|
||||
|
||||
$rule->save();
|
||||
|
||||
dispatch(fn () => $this->applyRule($rule));
|
||||
dispatch(fn () => $this->applyRule($rule))->onQueue('ssh');
|
||||
|
||||
return $rule;
|
||||
}
|
||||
@ -58,7 +58,7 @@ public function update(FirewallRule $rule, array $input): FirewallRule
|
||||
'status' => FirewallRuleStatus::UPDATING,
|
||||
]);
|
||||
|
||||
dispatch(fn () => $this->applyRule($rule));
|
||||
dispatch(fn () => $this->applyRule($rule))->onQueue('ssh');
|
||||
|
||||
return $rule;
|
||||
}
|
||||
@ -68,7 +68,7 @@ public function delete(FirewallRule $rule): void
|
||||
$rule->status = FirewallRuleStatus::DELETING;
|
||||
$rule->save();
|
||||
|
||||
dispatch(fn () => $this->applyRule($rule));
|
||||
dispatch(fn () => $this->applyRule($rule))->onQueue('ssh');
|
||||
}
|
||||
|
||||
protected function applyRule(FirewallRule $rule): void
|
||||
|
@ -44,7 +44,7 @@ function () use ($service, $input): void {
|
||||
$typeData['extensions'] = array_values(array_diff($typeData['extensions'], [$input['extension']]));
|
||||
$service->type_data = $typeData;
|
||||
$service->save();
|
||||
})->onConnection('ssh');
|
||||
})->onQueue('ssh-unique');
|
||||
|
||||
return $service;
|
||||
}
|
||||
|
@ -43,7 +43,7 @@ public function create(Site $site, array $input): Redirect
|
||||
$redirect->status = RedirectStatus::FAILED;
|
||||
$redirect->save();
|
||||
})
|
||||
->onConnection('ssh');
|
||||
->onQueue('ssh-unique');
|
||||
|
||||
return $redirect->refresh();
|
||||
}
|
||||
|
@ -27,6 +27,6 @@ public function delete(Site $site, Redirect $redirect): void
|
||||
})->catch(function () use ($redirect): void {
|
||||
$redirect->status = RedirectStatus::FAILED;
|
||||
$redirect->save();
|
||||
})->onConnection('ssh');
|
||||
})->onQueue('ssh-unique');
|
||||
}
|
||||
}
|
||||
|
@ -60,7 +60,7 @@ public function create(Site $site, array $input): void
|
||||
})->catch(function () use ($ssl): void {
|
||||
$ssl->status = SslStatus::FAILED;
|
||||
$ssl->save();
|
||||
})->onConnection('ssh');
|
||||
})->onQueue('ssh-unique');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -62,7 +62,7 @@ public function execute(Script $script, User $user, array $input): ScriptExecuti
|
||||
})->catch(function () use ($execution): void {
|
||||
$execution->status = ScriptExecutionStatus::FAILED;
|
||||
$execution->save();
|
||||
})->onConnection('ssh');
|
||||
})->onQueue('ssh');
|
||||
|
||||
return $execution;
|
||||
}
|
||||
|
@ -81,7 +81,7 @@ public function create(User $creator, Project $project, array $input): Server
|
||||
'error' => (string) $e,
|
||||
]);
|
||||
})
|
||||
->onConnection('ssh');
|
||||
->onQueue('ssh');
|
||||
|
||||
return $this->server;
|
||||
} catch (Exception $e) {
|
||||
|
@ -20,6 +20,6 @@ public function update(Server $server): void
|
||||
})->catch(function () use ($server): void {
|
||||
Notifier::send($server, new ServerUpdateFailed($server));
|
||||
$server->checkConnection();
|
||||
})->onConnection('ssh');
|
||||
})->onQueue('ssh-unique');
|
||||
}
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ public function install(Server $server, array $input): Service
|
||||
})->catch(function () use ($service): void {
|
||||
$service->status = ServiceStatus::INSTALLATION_FAILED;
|
||||
$service->save();
|
||||
})->onConnection('ssh');
|
||||
})->onQueue('ssh-unique');
|
||||
|
||||
return $service;
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ public function start(Service $service): void
|
||||
$service->status = ServiceStatus::FAILED;
|
||||
}
|
||||
$service->save();
|
||||
})->onConnection('ssh');
|
||||
})->onQueue('ssh');
|
||||
}
|
||||
|
||||
public function stop(Service $service): void
|
||||
@ -37,7 +37,7 @@ public function stop(Service $service): void
|
||||
$service->status = ServiceStatus::FAILED;
|
||||
}
|
||||
$service->save();
|
||||
})->onConnection('ssh');
|
||||
})->onQueue('ssh');
|
||||
}
|
||||
|
||||
public function restart(Service $service): void
|
||||
@ -53,7 +53,7 @@ public function restart(Service $service): void
|
||||
$service->status = ServiceStatus::FAILED;
|
||||
}
|
||||
$service->save();
|
||||
})->onConnection('ssh');
|
||||
})->onQueue('ssh');
|
||||
}
|
||||
|
||||
public function enable(Service $service): void
|
||||
@ -69,7 +69,7 @@ public function enable(Service $service): void
|
||||
$service->status = ServiceStatus::FAILED;
|
||||
}
|
||||
$service->save();
|
||||
})->onConnection('ssh');
|
||||
})->onQueue('ssh');
|
||||
}
|
||||
|
||||
public function disable(Service $service): void
|
||||
@ -85,7 +85,7 @@ public function disable(Service $service): void
|
||||
$service->status = ServiceStatus::FAILED;
|
||||
}
|
||||
$service->save();
|
||||
})->onConnection('ssh');
|
||||
})->onQueue('ssh');
|
||||
}
|
||||
|
||||
private function validate(Service $service): void
|
||||
|
@ -26,6 +26,6 @@ public function uninstall(Service $service): void
|
||||
})->catch(function () use ($service): void {
|
||||
$service->status = ServiceStatus::FAILED;
|
||||
$service->save();
|
||||
})->onConnection('ssh');
|
||||
})->onQueue('ssh-unique');
|
||||
}
|
||||
}
|
||||
|
@ -92,7 +92,7 @@ public function create(Server $server, array $input): Site
|
||||
$site->status = SiteStatus::INSTALLATION_FAILED;
|
||||
$site->save();
|
||||
Notifier::send($site, new SiteInstallationFailed($site));
|
||||
})->onConnection('ssh');
|
||||
})->onQueue('ssh-unique');
|
||||
|
||||
DB::commit();
|
||||
|
||||
|
@ -57,7 +57,7 @@ public function run(Site $site): Deployment
|
||||
$deployment->status = DeploymentStatus::FAILED;
|
||||
$deployment->save();
|
||||
Notifier::send($site, new DeploymentCompleted($deployment, $site));
|
||||
})->onConnection('ssh');
|
||||
})->onQueue('ssh-unique');
|
||||
|
||||
return $deployment;
|
||||
}
|
||||
|
@ -55,7 +55,7 @@ public function execute(Command $command, User $user, array $input): CommandExec
|
||||
})->catch(function () use ($execution): void {
|
||||
$execution->status = CommandExecutionStatus::FAILED;
|
||||
$execution->save();
|
||||
})->onConnection('ssh');
|
||||
})->onQueue('ssh');
|
||||
|
||||
return $execution;
|
||||
}
|
||||
|
@ -55,7 +55,7 @@ public function create(Server $server, array $input, ?Site $site = null): void
|
||||
$worker->save();
|
||||
})->catch(function () use ($worker): void {
|
||||
$worker->delete();
|
||||
})->onConnection('ssh');
|
||||
})->onQueue('ssh');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -55,7 +55,7 @@ public function edit(Worker $worker, array $input): void
|
||||
})->catch(function () use ($worker): void {
|
||||
$worker->status = WorkerStatus::FAILED;
|
||||
$worker->save();
|
||||
})->onConnection('ssh');
|
||||
})->onQueue('ssh');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -21,7 +21,7 @@ public function start(Worker $worker): void
|
||||
$handler->start($worker->id, $worker->site_id);
|
||||
$worker->status = WorkerStatus::RUNNING;
|
||||
$worker->save();
|
||||
})->onConnection('ssh');
|
||||
})->onQueue('ssh');
|
||||
}
|
||||
|
||||
public function stop(Worker $worker): void
|
||||
@ -36,7 +36,7 @@ public function stop(Worker $worker): void
|
||||
$handler->stop($worker->id, $worker->site_id);
|
||||
$worker->status = WorkerStatus::STOPPED;
|
||||
$worker->save();
|
||||
})->onConnection('ssh');
|
||||
})->onQueue('ssh');
|
||||
}
|
||||
|
||||
public function restart(Worker $worker): void
|
||||
@ -51,6 +51,6 @@ public function restart(Worker $worker): void
|
||||
$handler->restart($worker->id, $worker->site_id);
|
||||
$worker->status = WorkerStatus::RUNNING;
|
||||
$worker->save();
|
||||
})->onConnection('ssh');
|
||||
})->onQueue('ssh');
|
||||
}
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ public function handle(): void
|
||||
return;
|
||||
}
|
||||
$server->checkConnection();
|
||||
})->onConnection('ssh');
|
||||
})->onQueue('ssh');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ class Agent extends MobileDetect
|
||||
*
|
||||
* @var array<string, string>
|
||||
*/
|
||||
protected static $additionalOperatingSystems = [
|
||||
protected static array $additionalOperatingSystems = [
|
||||
'Windows' => 'Windows',
|
||||
'Windows NT' => 'Windows NT',
|
||||
'OS X' => 'Mac OS X',
|
||||
@ -29,7 +29,7 @@ class Agent extends MobileDetect
|
||||
*
|
||||
* @var array<string, string>
|
||||
*/
|
||||
protected static $additionalBrowsers = [
|
||||
protected static array $additionalBrowsers = [
|
||||
'Opera Mini' => 'Opera Mini',
|
||||
'Opera' => 'Opera|OPR',
|
||||
'Edge' => 'Edge|Edg',
|
||||
@ -50,14 +50,12 @@ class Agent extends MobileDetect
|
||||
*
|
||||
* @var array<string, mixed>
|
||||
*/
|
||||
protected $store = [];
|
||||
protected array $store = [];
|
||||
|
||||
/**
|
||||
* Get the platform name from the User Agent.
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function platform()
|
||||
public function platform(): ?string
|
||||
{
|
||||
return $this->retrieveUsingCacheOrResolve('paymently.platform', fn () => $this->findDetectionRulesAgainstUserAgent(
|
||||
$this->mergeRules(MobileDetect::getOperatingSystems(), static::$additionalOperatingSystems)
|
||||
|
@ -58,8 +58,7 @@ public function install(Request $request): RedirectResponse
|
||||
}
|
||||
|
||||
Plugins::cleanup();
|
||||
})
|
||||
->onConnection('default');
|
||||
})->onQueue('default');
|
||||
|
||||
return back()->with('info', 'Plugin is being installed...');
|
||||
}
|
||||
@ -89,8 +88,7 @@ public function uninstall(Request $request): RedirectResponse
|
||||
}
|
||||
|
||||
Plugins::cleanup();
|
||||
})
|
||||
->onConnection('default');
|
||||
})->onQueue('default');
|
||||
|
||||
return back()->with('warning', 'Plugin is being uninstalled...');
|
||||
}
|
||||
|
35
app/Providers/HorizonServiceProvider.php
Normal file
35
app/Providers/HorizonServiceProvider.php
Normal file
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
use Laravel\Horizon\Horizon;
|
||||
use Laravel\Horizon\HorizonApplicationServiceProvider;
|
||||
|
||||
class HorizonServiceProvider extends HorizonApplicationServiceProvider
|
||||
{
|
||||
/**
|
||||
* Bootstrap any application services.
|
||||
*/
|
||||
public function boot(): void
|
||||
{
|
||||
parent::boot();
|
||||
|
||||
// Horizon::routeSmsNotificationsTo('15556667777');
|
||||
// Horizon::routeMailNotificationsTo('example@example.com');
|
||||
// Horizon::routeSlackNotificationsTo('slack-webhook-url', '#channel');
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the Horizon gate.
|
||||
*
|
||||
* This gate determines who can access Horizon in non-local environments.
|
||||
*/
|
||||
protected function gate(): void
|
||||
{
|
||||
Gate::define('viewHorizon', function (?User $user = null) {
|
||||
return $user?->isAdmin();
|
||||
});
|
||||
}
|
||||
}
|
@ -34,15 +34,12 @@ public function createRules(array $input): array
|
||||
public function connect(): bool
|
||||
{
|
||||
try {
|
||||
ds($this->getApiUrl());
|
||||
$res = Http::withToken($this->data()['token'])
|
||||
->get($this->getApiUrl().'/version');
|
||||
} catch (Exception) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ds($res->status());
|
||||
|
||||
return $res->successful();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user