17 lines
1.6 KiB
PHP
17 lines
1.6 KiB
PHP
<?php
|
|
$root=realpath((string)getenv('STOCK_RECEIPT_ROOT'));$file=realpath($argv[1]??'');
|
|
if(!$root||!$file||dirname($file)!==$root)throw new RuntimeException('Unexpected private worker');
|
|
require getcwd().'/vendor/autoload.php';$app=require getcwd().'/bootstrap/app.php';$app->make(Illuminate\Contracts\Console\Kernel::class)->bootstrap();
|
|
$db=Illuminate\Support\Facades\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=App\Models\User::findOrFail($input['actor']);auth()->guard()->setUser($actor);
|
|
file_put_contents($file.'.ready','ready');
|
|
$start=hrtime(true);
|
|
try{$receipt=app(App\Services\ReceiptWorkflow::class)->confirm($actor,App\Models\PurchaseOrder::findOrFail($input['order']),$input['payload']);
|
|
$result=['status'=>200,'receipt_id'=>$receipt->id];
|
|
}catch(Illuminate\Validation\ValidationException){$result=['status'=>422];}
|
|
catch(Symfony\Component\HttpKernel\Exception\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));
|