mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-02 22:46:16 +00:00
init
This commit is contained in:
49
app/Jobs/Queue/Deploy.php
Normal file
49
app/Jobs/Queue/Deploy.php
Normal file
@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs\Queue;
|
||||
|
||||
use App\Enums\QueueStatus;
|
||||
use App\Events\Broadcast;
|
||||
use App\Jobs\Job;
|
||||
use App\Models\Queue;
|
||||
|
||||
class Deploy extends Job
|
||||
{
|
||||
protected Queue $worker;
|
||||
|
||||
public function __construct(Queue $worker)
|
||||
{
|
||||
$this->worker = $worker;
|
||||
}
|
||||
|
||||
public function handle(): void
|
||||
{
|
||||
$this->worker->server->processManager()->handler()->create(
|
||||
$this->worker->id,
|
||||
$this->worker->command,
|
||||
$this->worker->user,
|
||||
$this->worker->auto_start,
|
||||
$this->worker->auto_restart,
|
||||
$this->worker->numprocs,
|
||||
$this->worker->log_file,
|
||||
$this->worker->site_id
|
||||
);
|
||||
$this->worker->status = QueueStatus::RUNNING;
|
||||
$this->worker->save();
|
||||
event(
|
||||
new Broadcast('deploy-queue-finished', [
|
||||
'queue' => $this->worker,
|
||||
])
|
||||
);
|
||||
}
|
||||
|
||||
public function failed(): void
|
||||
{
|
||||
$this->worker->delete();
|
||||
event(
|
||||
new Broadcast('deploy-queue-failed', [
|
||||
'queue' => $this->worker,
|
||||
])
|
||||
);
|
||||
}
|
||||
}
|
37
app/Jobs/Queue/GetLogs.php
Normal file
37
app/Jobs/Queue/GetLogs.php
Normal file
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs\Queue;
|
||||
|
||||
use App\Events\Broadcast;
|
||||
use App\Jobs\Job;
|
||||
use App\Models\Queue;
|
||||
|
||||
class GetLogs extends Job
|
||||
{
|
||||
protected Queue $worker;
|
||||
|
||||
public function __construct(Queue $worker)
|
||||
{
|
||||
$this->worker = $worker;
|
||||
}
|
||||
|
||||
public function handle(): void
|
||||
{
|
||||
$logs = $this->worker->server->processManager()->handler()->getLogs($this->worker->log_file);
|
||||
event(
|
||||
new Broadcast('get-logs-finished', [
|
||||
'id' => $this->worker->id,
|
||||
'logs' => $logs,
|
||||
])
|
||||
);
|
||||
}
|
||||
|
||||
public function failed(): void
|
||||
{
|
||||
event(
|
||||
new Broadcast('get-logs-failed', [
|
||||
'message' => __('Failed to download the logs!'),
|
||||
])
|
||||
);
|
||||
}
|
||||
}
|
68
app/Jobs/Queue/Manage.php
Normal file
68
app/Jobs/Queue/Manage.php
Normal file
@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs\Queue;
|
||||
|
||||
use App\Events\Broadcast;
|
||||
use App\Jobs\Job;
|
||||
use App\Models\Queue;
|
||||
|
||||
class Manage extends Job
|
||||
{
|
||||
protected Queue $worker;
|
||||
|
||||
protected string $action;
|
||||
|
||||
protected string $successStatus;
|
||||
|
||||
protected string $failStatus;
|
||||
|
||||
protected string $failMessage;
|
||||
|
||||
public function __construct(
|
||||
Queue $worker,
|
||||
string $action,
|
||||
string $successStatus,
|
||||
string $failStatus,
|
||||
string $failMessage,
|
||||
) {
|
||||
$this->worker = $worker;
|
||||
$this->action = $action;
|
||||
$this->successStatus = $successStatus;
|
||||
$this->failStatus = $failStatus;
|
||||
$this->failMessage = $failMessage;
|
||||
}
|
||||
|
||||
public function handle(): void
|
||||
{
|
||||
switch ($this->action) {
|
||||
case 'start':
|
||||
$this->worker->server->processManager()->handler()->start($this->worker->id, $this->worker->site_id);
|
||||
break;
|
||||
case 'stop':
|
||||
$this->worker->server->processManager()->handler()->stop($this->worker->id, $this->worker->site_id);
|
||||
break;
|
||||
case 'restart':
|
||||
$this->worker->server->processManager()->handler()->restart($this->worker->id, $this->worker->site_id);
|
||||
break;
|
||||
}
|
||||
$this->worker->status = $this->successStatus;
|
||||
$this->worker->save();
|
||||
event(
|
||||
new Broadcast('manage-queue-finished', [
|
||||
'queue' => $this->worker,
|
||||
])
|
||||
);
|
||||
}
|
||||
|
||||
public function failed(): void
|
||||
{
|
||||
$this->worker->status = $this->failStatus;
|
||||
$this->worker->save();
|
||||
event(
|
||||
new Broadcast('manage-queue-failed', [
|
||||
'message' => $this->failMessage,
|
||||
'queue' => $this->worker,
|
||||
])
|
||||
);
|
||||
}
|
||||
}
|
41
app/Jobs/Queue/Remove.php
Normal file
41
app/Jobs/Queue/Remove.php
Normal file
@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs\Queue;
|
||||
|
||||
use App\Enums\QueueStatus;
|
||||
use App\Events\Broadcast;
|
||||
use App\Jobs\Job;
|
||||
use App\Models\Queue;
|
||||
|
||||
class Remove extends Job
|
||||
{
|
||||
protected Queue $worker;
|
||||
|
||||
public function __construct(Queue $worker)
|
||||
{
|
||||
$this->worker = $worker;
|
||||
}
|
||||
|
||||
public function handle(): void
|
||||
{
|
||||
$this->worker->server->processManager()->handler()->delete($this->worker->id, $this->worker->site_id);
|
||||
$this->worker->delete();
|
||||
event(
|
||||
new Broadcast('remove-queue-finished', [
|
||||
'id' => $this->worker->id,
|
||||
])
|
||||
);
|
||||
}
|
||||
|
||||
public function failed(): void
|
||||
{
|
||||
$this->worker->status = QueueStatus::FAILED;
|
||||
$this->worker->save();
|
||||
event(
|
||||
new Broadcast('remove-queue-failed', [
|
||||
'message' => __('Failed to delete worker!'),
|
||||
'id' => $this->worker->id,
|
||||
])
|
||||
);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user