34 lines
1.3 KiB
PHP
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']);
|
|
}
|
|
}
|
|
}
|