feat(阶段三): 实现配置同步功能
- 创建 TerminalSyncService 服务类 - 实现配置快照生成(包含终端、知识库、提示词) - 创建 SyncTerminalConfigJob 异步任务 - 实现重试机制(最多3次,指数退避) - 创建 SyncConfigAction(单个和批量同步) - 在终端列表页添加同步状态列 - 在终端详情页添加同步历史展示 - 支持同步状态追踪(pending/syncing/synced/failed)
This commit is contained in:
71
app/Filament/Actions/SyncConfigAction.php
Normal file
71
app/Filament/Actions/SyncConfigAction.php
Normal file
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Actions;
|
||||
|
||||
use App\Models\Terminal;
|
||||
use App\Services\TerminalSyncService;
|
||||
use Filament\Tables\Actions\Action;
|
||||
use Filament\Tables\Actions\BulkAction;
|
||||
use Filament\Notifications\Notification;
|
||||
|
||||
/**
|
||||
* 同步终端配置Action
|
||||
*/
|
||||
class SyncConfigAction
|
||||
{
|
||||
/**
|
||||
* 创建单个终端同步Action
|
||||
*
|
||||
* @return Action
|
||||
*/
|
||||
public static function make(): Action
|
||||
{
|
||||
return Action::make('sync')
|
||||
->label('同步配置')
|
||||
->icon('heroicon-o-arrow-path')
|
||||
->color('success')
|
||||
->requiresConfirmation()
|
||||
->modalHeading('同步终端配置')
|
||||
->modalDescription('确定要将配置同步到此终端吗?')
|
||||
->modalSubmitActionLabel('确认同步')
|
||||
->action(function (Terminal $record) {
|
||||
$service = app(TerminalSyncService::class);
|
||||
$log = $service->syncConfiguration($record);
|
||||
|
||||
Notification::make()
|
||||
->title('同步任务已启动')
|
||||
->body("终端 {$record->name} 的配置同步任务已加入队列")
|
||||
->success()
|
||||
->send();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建批量同步Action
|
||||
*
|
||||
* @return BulkAction
|
||||
*/
|
||||
public static function makeBulk(): BulkAction
|
||||
{
|
||||
return BulkAction::make('batchSync')
|
||||
->label('批量同步')
|
||||
->icon('heroicon-o-arrow-path')
|
||||
->color('success')
|
||||
->requiresConfirmation()
|
||||
->modalHeading('批量同步终端配置')
|
||||
->modalDescription(fn ($records) => "确定要同步 {$records->count()} 个终端的配置吗?")
|
||||
->modalSubmitActionLabel('确认同步')
|
||||
->action(function ($records) {
|
||||
$service = app(TerminalSyncService::class);
|
||||
$terminalIds = $records->pluck('id')->toArray();
|
||||
$logs = $service->batchSync($terminalIds);
|
||||
|
||||
Notification::make()
|
||||
->title('批量同步任务已启动')
|
||||
->body("已为 " . count($logs) . " 个终端创建同步任务")
|
||||
->success()
|
||||
->send();
|
||||
})
|
||||
->deselectRecordsAfterCompletion();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user