Skip to content

Commit

Permalink
stably
Browse files Browse the repository at this point in the history
  • Loading branch information
MouseZver committed Mar 21, 2021
1 parent eebb311 commit 0e2a133
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 27 deletions.
32 changes: 12 additions & 20 deletions example/failed_order_pending.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,18 @@
'email' => 'mail@mail.ru',
'phone' => 'phone',
'accountId' => $id_account,

'id' => &$id_insert_order
];

try
while ( true )
{
$leeloo_order_id = $leeloo -> orderPending( $data, $offer );

$db -> query( 'INSERT... order pay, status = pending AND leeloo_order_id = {$leeloo_order_id}' );

$id_insert_order = $db -> last_insert_id();
}
catch ( \Nouvu\Leeloo\LeelooOrderFailed $e )
{
$logger -> set( $e -> getMessage() ) -> set( json_encode ( $leeloo -> getResponse() ) );

$db -> query( 'INSERT... order pay, status = pending AND leeloo_order_id = null' );

$id_insert_order = $db -> last_insert_id();

$leeloo -> saveFailure();
}

try
{
$leeloo_order_id = $leeloo -> orderPending( $data, $offer );

break;
}
catch ( \Nouvu\Leeloo\LeelooOrderFailed $e )
{
sleep ( 2 );
}
}
14 changes: 10 additions & 4 deletions src/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ public function __construct ( array $leeloo, bool $send = true )
'delete' => fn(): bool => false,
'update' => fn(): bool => false,
'insert' => fn(): bool => false,
'order'
],
'send' => $send
] );
Expand Down Expand Up @@ -203,20 +202,27 @@ public function saveFailure(): void
{
[ 'method' => $method, 'args' => $args ] = $this -> getVars();

if ( $method == 'orderPending' )
{
throw new LeelooException( 'The orderPending method is not allowed for data processing' );
}

$this -> getData( 'sql_callback.insert' )( $method, json_encode ( $args ), json_encode ( $this -> getResponse() ) );
}

public function cron( array $queue ): void
{
$this -> cron = true;

$this -> id = $queue['id'];
$this -> id = ( int ) $queue['id'];

$data = json_decode ( $queue['data'], true );

try
{
$this -> {$queue['method']}( ...$queue['data'] );
$this -> {$queue['method']}( ...$data );

if ( in_array ( $queue['method'], [ 'orderPending', 'orderUpdate' ] ) )
if ( $queue['method'] == 'orderUpdate' )
{
$this -> getData( 'sql_callback.delete' )( $this -> id );
}
Expand Down
8 changes: 5 additions & 3 deletions src/Core.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,18 @@ protected function tag( string $api_name, string $type, array $args ): self

$status_name = $this -> getDataTag( 'status' );

$leeloo_id = $this -> getDataTag( 'leeloo_id' );

$status_id = $this -> getData( 'leeloo.tags.' . $status_name );

if ( is_null ( $status_id ) )
{
throw new LeelooException( 'Not found status id for tag: ' . $status_name );
}

$this -> setVars( __FUNCTION__, func_get_args () );
$this -> setVars( __FUNCTION__, [ $api_name, $type, [ $leeloo_id, $status_name ] ] );

$link = sprintf ( static :: API[$api_name], $this -> getDataTag( 'leeloo_id' ), $type );
$link = sprintf ( static :: API[$api_name], $leeloo_id, $type );

$this -> send( $link, [ 'tag_id' => $status_id, 'api' => $api_name ], 'PUT' );

Expand Down Expand Up @@ -114,7 +116,7 @@ protected function getVars(): array

protected function VerifyOrderStatus(): void
{
if ( empty ( $this -> response['status'] ) )
if ( empty ( $this -> getResponse()['status'] ) )
{
throw new LeelooOrderFailed( 'The sent order failed' );
}
Expand Down

0 comments on commit 0e2a133

Please sign in to comment.