41 lines
2.0 KiB
PHP
41 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use Illuminate\Console\Command;
|
|
use Modules\EcommerceFinance\Repositories\GenericBusinessMirrorRepository;
|
|
use Modules\EcommerceFinance\Services\BusinessMirrorDatasetRegistry;
|
|
use Throwable;
|
|
|
|
class BusinessMirrorStatus extends Command
|
|
{
|
|
protected $signature = 'business-mirror:status {dataset?} {--json}';
|
|
protected $description = '只读查看已登记镜像的启用、首次完成和最近同步状态';
|
|
|
|
public function handle(BusinessMirrorDatasetRegistry $datasets, GenericBusinessMirrorRepository $mirror): int
|
|
{
|
|
try {
|
|
$requested = $this->argument('dataset');
|
|
$selected = $requested ? [$requested => $datasets->get($requested)] : $datasets->all();
|
|
$rows = [];
|
|
foreach ($selected as $key => $dataset) {
|
|
$state = $mirror->state($dataset);
|
|
$rows[] = [
|
|
'dataset' => $key, 'enabled' => $datasets->scheduled($key),
|
|
'initial_completed' => ($state['initial_completed_at'] ?? null) !== null,
|
|
'status' => $state['status'] ?? ($datasets->automaticInitialSyncAllowed($key) ? 'queued' : 'not_initialized'),
|
|
'last_attempted_at' => $state['last_attempted_at'] ?? null,
|
|
'last_succeeded_at' => $state['last_succeeded_at'] ?? null,
|
|
'error_code' => $state['last_error_code'] ?? null,
|
|
];
|
|
}
|
|
if ($this->option('json')) $this->line(json_encode($rows, JSON_UNESCAPED_UNICODE | JSON_THROW_ON_ERROR));
|
|
else $this->table(['数据集', '启用', '首次完成', '状态', '最近尝试', '最近完成', '错误类型'], array_map(fn ($r) => array_values($r), $rows));
|
|
return self::SUCCESS;
|
|
} catch (Throwable) {
|
|
$this->error('无法读取镜像状态,请确认共享系统数据库和业务镜像库已接入。');
|
|
return self::FAILURE;
|
|
}
|
|
}
|
|
}
|