refactor(batch): 去重阻断warning组装提炼BatchDispatchWarning并加单测
This commit is contained in:
39
app/Support/BatchDispatchWarning.php
Normal file
39
app/Support/BatchDispatchWarning.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Support;
|
||||
|
||||
class BatchDispatchWarning
|
||||
{
|
||||
/**
|
||||
* @return array{warning:string, warning_link_href?:string, warning_link_label?:string, warning_copy_text?:string, warning_copy_label?:string}
|
||||
*/
|
||||
public static function build(
|
||||
string $actionLabel,
|
||||
string $runId,
|
||||
string $batchType,
|
||||
): array {
|
||||
$actionLabel = trim((string) $actionLabel);
|
||||
$runId = trim((string) $runId);
|
||||
$batchType = trim((string) $batchType);
|
||||
|
||||
$msg = '检测到刚刚已提交过同一批次的' . $actionLabel . '任务(1 分钟内)。为避免重复投递,本次未再次提交。';
|
||||
|
||||
$payload = [
|
||||
'warning' => $msg,
|
||||
];
|
||||
|
||||
if ($runId === '') {
|
||||
return $payload;
|
||||
}
|
||||
|
||||
$short = RunId::short($runId, $batchType === 'bmpa' ? 7 : 6, 4);
|
||||
$payload['warning'] = '检测到刚刚已提交过同一批次的' . $actionLabel . '任务(1 分钟内,run_id=' . $short . ')。为避免重复投递,本次未再次提交。';
|
||||
|
||||
$payload['warning_link_href'] = '/admin/platform-batches/show?type=' . $batchType . '&run_id=' . urlencode($runId);
|
||||
$payload['warning_link_label'] = '进入上次批次复盘';
|
||||
$payload['warning_copy_text'] = $runId;
|
||||
$payload['warning_copy_label'] = '复制run_id';
|
||||
|
||||
return $payload;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user