make(Kernel::class)->bootstrap(); $db = DB::connection(); $i = $db->selectOne("SELECT current_database() AS name,current_user AS role,current_setting('cluster_name') AS cluster"); if (! preg_match('/^compras_receipts_test_([a-f0-9]{12})$/D', $i->name, $m) || $i->role !== 'stock_receipt_qa_'.$m[1] || $i->cluster !== 'sgf_modular_regression_'.getenv('SGF_ISOLATED_REGRESSION_RUN')) { throw new RuntimeException('Wrong receipt worker database'); } $input = json_decode(file_get_contents($file), true, 512, JSON_THROW_ON_ERROR); $db->select("SELECT set_config('application_name',?,false)", [$input['application']]); $db->statement("SET lock_timeout='8s'"); $db->statement("SET statement_timeout='12s'"); $actor = User::findOrFail($input['actor']); auth()->guard()->setUser($actor); file_put_contents($file.'.ready', 'ready'); $start = hrtime(true); try { $receipt = app(ReceiptWorkflow::class)->confirm($actor, PurchaseOrder::findOrFail($input['order']), $input['payload']); $result = ['status' => 200, 'receipt_id' => $receipt->id]; } catch (ValidationException) { $result = ['status' => 422]; } catch (HttpExceptionInterface $e) { $result = ['status' => $e->getStatusCode()]; } $result['elapsed_ms'] = round((hrtime(true) - $start) / 1e6, 3); file_put_contents($file.'.result', json_encode($result, JSON_THROW_ON_ERROR));