428b7b0f01
Клиент во время сбора видит место в общей очереди (пока ждёт) и текущий этап (пока идёт). Очередь — длина общей Redis-очереди (честное ожидание, без RLS, одинаково dev/прод). Этапы пишет сам движок через RunProgressChannel: поиск (анализ→справочники→федералы→сбор→отбор), изучение — по каждому элементу. - миграция progress (jsonb) на autopodbor_runs + cast - RunResource отдаёт queue_position (AutopodborQueue) и progress - RunProgressChannel (синглтон), джобы привязывают его к своему прогону - SearchStages + инструментовка LiveFindCompetitors и RealCompetitorAgent - 16 тестов (Feature+Unit), все зелёные Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
66 lines
2.8 KiB
PHP
66 lines
2.8 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use App\Models\AutopodborRun;
|
|
use App\Models\Tenant;
|
|
use App\Models\User;
|
|
use App\Services\Autopodbor\AutopodborQueue;
|
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\Queue;
|
|
use Tests\Concerns\SharesSupplierPdo;
|
|
|
|
uses(DatabaseTransactions::class, SharesSupplierPdo::class);
|
|
beforeEach(fn () => Queue::fake());
|
|
|
|
it('прогон в очереди отдаёт queue_position = длине общей очереди (честное ожидание)', function () {
|
|
$tenant = Tenant::factory()->create();
|
|
$user = User::factory()->create(['tenant_id' => $tenant->id]);
|
|
DB::statement('SET app.current_tenant_id = '.$tenant->id);
|
|
$run = AutopodborRun::create([
|
|
'tenant_id' => $tenant->id, 'kind' => 'search', 'status' => 'queued',
|
|
'region_code' => 16, 'params' => [],
|
|
]);
|
|
|
|
// Общая очередь автоподбора = 3 задачи (глобально, у всех клиентов).
|
|
$this->mock(AutopodborQueue::class)->shouldReceive('pending')->andReturn(3);
|
|
|
|
$this->actingAs($user)->getJson("/api/autopodbor/runs/{$run->id}")
|
|
->assertOk()
|
|
->assertJsonPath('data.queue_position', 3)
|
|
->assertJsonPath('data.progress', null);
|
|
});
|
|
|
|
it('идущий прогон отдаёт progress {stage,total,label}, queue_position пуст', function () {
|
|
$tenant = Tenant::factory()->create();
|
|
$user = User::factory()->create(['tenant_id' => $tenant->id]);
|
|
DB::statement('SET app.current_tenant_id = '.$tenant->id);
|
|
$run = AutopodborRun::create([
|
|
'tenant_id' => $tenant->id, 'kind' => 'search', 'status' => 'running',
|
|
'region_code' => 16, 'params' => [],
|
|
'progress' => ['stage' => 2, 'total' => 4, 'label' => 'Ищем фирмы в справочниках'],
|
|
]);
|
|
|
|
$this->actingAs($user)->getJson("/api/autopodbor/runs/{$run->id}")
|
|
->assertOk()
|
|
->assertJsonPath('data.progress.stage', 2)
|
|
->assertJsonPath('data.progress.total', 4)
|
|
->assertJsonPath('data.progress.label', 'Ищем фирмы в справочниках')
|
|
->assertJsonPath('data.queue_position', null);
|
|
});
|
|
|
|
it('завершённый прогон: queue_position пуст (очередь его не касается)', function () {
|
|
$tenant = Tenant::factory()->create();
|
|
$user = User::factory()->create(['tenant_id' => $tenant->id]);
|
|
DB::statement('SET app.current_tenant_id = '.$tenant->id);
|
|
$run = AutopodborRun::create([
|
|
'tenant_id' => $tenant->id, 'kind' => 'search', 'status' => 'done',
|
|
'region_code' => 16, 'params' => [],
|
|
]);
|
|
|
|
$this->actingAs($user)->getJson("/api/autopodbor/runs/{$run->id}")
|
|
->assertOk()
|
|
->assertJsonPath('data.queue_position', null);
|
|
});
|