make(\Illuminate\Contracts\Console\Kernel::class)->bootstrap(); \App\Shared\Testing\TestingDatabaseGuard::assertSafe(); $input = json_decode(stream_get_contents(STDIN), true, 32, JSON_THROW_ON_ERROR); $context = app(\App\Shared\Context\CompanyContext::class); $context->selectFor($input['actor'], $input['tenant'], $input['company'], $input['unit']); try { $result = \Illuminate\Support\Facades\DB::transaction(function () use ($input) { if ($input['hold'] ?? false) { \Illuminate\Support\Facades\DB::table('companies')->where('id', $input['company'])->lockForUpdate()->firstOrFail(); echo "LOCK_ACQUIRED\n"; flush(); usleep(2000000); } return app(\App\Modules\Services\ServiceWorkflow::class)->save('clients', $input['id'] ?? null, $input['actor'], $input['data'], $input['key']); }); echo json_encode(['status' => 200, 'result' => $result], JSON_THROW_ON_ERROR).PHP_EOL; } catch (\Symfony\Component\HttpKernel\Exception\HttpExceptionInterface $exception) { echo json_encode(['status' => $exception->getStatusCode()], JSON_THROW_ON_ERROR).PHP_EOL; } catch (\Throwable) { fwrite(STDERR, "Synthetic concurrency worker failed; no request payload displayed.\n"); exit(1); }