多个A2C任务时防止同时同步引起错误
This commit is contained in:
@@ -37,6 +37,8 @@ class SplitNodeHealthService
|
||||
|
||||
/**
|
||||
* 当前是否适合向 Node 提交新 Browser 任务
|
||||
*
|
||||
* A2C 等 antiBot 任务走 real profile,应参考 queueReal 而非 standard 队列。
|
||||
*/
|
||||
public static function canAcceptWork(): bool
|
||||
{
|
||||
@@ -47,33 +49,61 @@ class SplitNodeHealthService
|
||||
if (!empty($stats['shuttingDown'])) {
|
||||
return false;
|
||||
}
|
||||
$queue = is_array($stats['queue'] ?? null) ? $stats['queue'] : [];
|
||||
$config = is_array($stats['config'] ?? null) ? $stats['config'] : [];
|
||||
$queued = (int) ($queue['queued'] ?? 0);
|
||||
$active = (int) ($queue['active'] ?? 0);
|
||||
$max = max(1, (int) ($config['maxConcurrentBrowsers'] ?? ($queue['max'] ?? 4)));
|
||||
|
||||
$snapshot = self::resolveQueueSnapshot($stats);
|
||||
$threshold = SplitSyncConfigService::getNodeQueueSkipThreshold();
|
||||
if ($queued >= $threshold) {
|
||||
if ($snapshot['queued'] >= $threshold) {
|
||||
return false;
|
||||
}
|
||||
return $active < $max;
|
||||
|
||||
return $snapshot['active'] < $snapshot['max'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{queued:int,active:int,max:int}
|
||||
* @return array{queued:int,active:int,max:int,profile:string}
|
||||
*/
|
||||
public static function getQueueSnapshot(): array
|
||||
{
|
||||
$stats = self::fetchStats();
|
||||
if ($stats === null) {
|
||||
return ['queued' => 0, 'active' => 0, 'max' => 0];
|
||||
return ['queued' => 0, 'active' => 0, 'max' => 0, 'profile' => 'real'];
|
||||
}
|
||||
$queue = is_array($stats['queue'] ?? null) ? $stats['queue'] : [];
|
||||
$config = is_array($stats['config'] ?? null) ? $stats['config'] : [];
|
||||
|
||||
$snapshot = self::resolveQueueSnapshot($stats);
|
||||
return [
|
||||
'queued' => (int) ($queue['queued'] ?? 0),
|
||||
'active' => (int) ($queue['active'] ?? 0),
|
||||
'max' => max(1, (int) ($config['maxConcurrentBrowsers'] ?? ($queue['max'] ?? 4))),
|
||||
'queued' => $snapshot['queued'],
|
||||
'active' => $snapshot['active'],
|
||||
'max' => $snapshot['max'],
|
||||
'profile' => $snapshot['profile'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 优先使用 real 队列(antiBot / A2C),无数据时回退 standard
|
||||
*
|
||||
* @param array<string, mixed> $stats
|
||||
* @return array{queued:int,active:int,max:int,profile:string}
|
||||
*/
|
||||
private static function resolveQueueSnapshot(array $stats): array
|
||||
{
|
||||
$config = is_array($stats['config'] ?? null) ? $stats['config'] : [];
|
||||
$queueReal = is_array($stats['queueReal'] ?? null) ? $stats['queueReal'] : [];
|
||||
if ($queueReal !== []) {
|
||||
return [
|
||||
'queued' => (int) ($queueReal['queued'] ?? 0),
|
||||
'active' => (int) ($queueReal['active'] ?? 0),
|
||||
'max' => max(1, (int) ($config['maxConcurrentBrowsersReal'] ?? ($queueReal['max'] ?? 2))),
|
||||
'profile' => 'real',
|
||||
];
|
||||
}
|
||||
|
||||
$queue = is_array($stats['queue'] ?? null) ? $stats['queue'] : [];
|
||||
|
||||
return [
|
||||
'queued' => (int) ($queue['queued'] ?? 0),
|
||||
'active' => (int) ($queue['active'] ?? 0),
|
||||
'max' => max(1, (int) ($config['maxConcurrentBrowsers'] ?? ($queue['max'] ?? 4))),
|
||||
'profile' => 'standard',
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user