CaiWuXiTong/app/Console/Commands/SyncBillOffsetMirror.php

70 lines
2.6 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Log;
use Modules\EcommerceFinance\Services\BusinessMirrorSynchronizer;
use Throwable;
/**
* 账单冲减页面(500112 冲减收入)专用同步命令。
*
* 现有 business-mirror:sync-tables 走通用调度,本命令只盯这一个 dataset,
* 调度粒度更细、不被 business_data.datasets 中的 placement 策略过滤掉。
* 镜像表 ops_jst_original_bill_info、列、索引、watermark 已在
* config/upstream_mirrors.php 配置;这里只负责按稳定游标续传。
*/
class SyncBillOffsetMirror extends Command
{
protected $signature = 'business-mirror:sync-bill-offset
{--full : 执行或继续首次全量同步}
{--batch= : 每批最多读取行数,默认取 config(upstream_mirrors.table_sync.batch_size)}
{--max-batches= : 本轮最多批次数,0 表示直到完成}';
protected $description = '将经营分析副本库的账单冲减(500112 冲减收入)数据续传到共享业务镜像库';
private const DATASET = 'operations_replica.rpt.jst_originalBillInfo';
public function handle(BusinessMirrorSynchronizer $synchronizer): int
{
if (! (bool) config('upstream_mirrors.refresh_enabled', false) && ! $this->option('full')) {
return self::SUCCESS;
}
try {
$result = $synchronizer->sync(
self::DATASET,
(bool) $this->option('full'),
$this->option('batch') === null ? null : (int) $this->option('batch'),
$this->option('max-batches') === null ? null : (int) $this->option('max-batches'),
);
} catch (Throwable $exception) {
Log::error('账单冲减共享镜像同步失败。', [
'dataset' => self::DATASET,
'exception' => $exception::class,
'message' => $exception->getMessage(),
]);
$this->error('账单冲减共享镜像同步失败,已保留上一版共享数据。');
return self::FAILURE;
}
if ($result['status'] === 'requires_full_sync') {
$this->warn('账单冲减共享镜像尚未执行首次全量同步,请显式使用 --full。');
return self::SUCCESS;
}
$this->info(sprintf(
'账单冲减镜像(%s):%s,本轮 %d 批,累计处理 %d 行。',
self::DATASET,
$result['status'] === 'succeeded' ? '同步完成' : '同步进行中',
$result['batches'],
$result['rows'],
));
return self::SUCCESS;
}
}