new changes
This commit is contained in:
54
panel-api/app/Modules/Jobs/CommandOrchestrator.php
Normal file
54
panel-api/app/Modules/Jobs/CommandOrchestrator.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace App\Modules\Jobs;
|
||||
|
||||
class CommandOrchestrator
|
||||
{
|
||||
private array $acceptedTypes = [
|
||||
'SITE_CREATE',
|
||||
'SITE_UPDATE',
|
||||
'SITE_DELETE',
|
||||
'DOMAIN_ADD',
|
||||
'DOMAIN_REMOVE',
|
||||
'SSL_ISSUE',
|
||||
'SSL_APPLY',
|
||||
'SSL_RENEW',
|
||||
'WEBSERVER_RELOAD',
|
||||
'FILE_LIST',
|
||||
'FILE_READ',
|
||||
'FILE_WRITE',
|
||||
'CRON_LIST',
|
||||
'CRON_CREATE',
|
||||
'CRON_DELETE',
|
||||
'FIREWALL_RULE_LIST',
|
||||
'DOCKER_DEPLOY',
|
||||
'PLUGIN_INSTALL',
|
||||
'PLUGIN_UPDATE',
|
||||
'PLUGIN_REMOVE',
|
||||
'FIREWALL_RULE_ADD',
|
||||
'FIREWALL_RULE_DELETE',
|
||||
'BACKUP_RUN',
|
||||
'BACKUP_RESTORE',
|
||||
];
|
||||
|
||||
public function dispatch(array $commandEnvelope): array
|
||||
{
|
||||
$type = (string) ($commandEnvelope['type'] ?? '');
|
||||
if (!in_array($type, $this->acceptedTypes, true)) {
|
||||
return [
|
||||
'job_status' => 'rejected',
|
||||
'error' => 'Unsupported command type',
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
'job_status' => 'queued',
|
||||
'job_id' => uniqid('job_', true),
|
||||
'tenant_id' => $commandEnvelope['tenant_id'] ?? null,
|
||||
'type' => $type,
|
||||
'idempotency_key' => $commandEnvelope['idempotency_key'] ?? null,
|
||||
'args' => $commandEnvelope['args'] ?? [],
|
||||
'message' => 'Command accepted for execution plane dispatch',
|
||||
];
|
||||
}
|
||||
}
|
||||
25
panel-api/app/Modules/Jobs/JobController.php
Normal file
25
panel-api/app/Modules/Jobs/JobController.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Modules\Jobs;
|
||||
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Routing\Controller;
|
||||
|
||||
class JobController extends Controller
|
||||
{
|
||||
public function __construct(private readonly CommandOrchestrator $orchestrator)
|
||||
{
|
||||
}
|
||||
|
||||
public function dispatch(Request $request): JsonResponse
|
||||
{
|
||||
$tenantId = (string) $request->attributes->get('tenant_id', '');
|
||||
$payload = $request->all();
|
||||
$payload['tenant_id'] = $tenantId;
|
||||
|
||||
$result = $this->orchestrator->dispatch($payload);
|
||||
|
||||
return response()->json(['data' => $result], 202);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user