Files
Investidor-V2/app/Services/Mne/CompatibilityShadow.php
T
nala 3dc7c5c649
tests / ci (push) Canceled after 0s
commit 30/9
2026-09-30 09:05:43 +02:00

34 lines
1.3 KiB
PHP

<?php
namespace App\Services\Mne;
use App\Jobs\CompareMneBusiness;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
final class CompatibilityShadow
{
/** Invoke only after authorization; optional comparison must never affect the response. */
public function schedule(string $businessId): void
{
if (! config('existing-business.compatibility_shadow', false)) {
return;
}
try {
$control = DB::transaction(fn () => DB::table('mne.compatibility_controls')->where('capability', 'shadow')->first());
if (! $control || ! $control->enabled || (hexdec(substr(hash('sha256', $businessId), 0, 6)) % 100) >= $control->percentage) {
return;
}
$connection = (string) config('existing-business.shadow_queue', 'database');
if (config('queue.connections.'.$connection.'.driver') !== 'database') {
Log::info('mne.compatibility.shadow', ['outcome' => 'async_queue_required']);
return;
}
CompareMneBusiness::dispatch($businessId)->onConnection($connection)->onQueue('mne-shadow')->afterCommit();
} catch (\Throwable) {
Log::info('mne.compatibility.shadow', ['outcome' => 'dispatch_error']);
}
}
}