improve resiliency of bank transaction processing

This commit is contained in:
David Bomba 2023-06-25 14:44:38 +10:00
parent fdc67cd5fb
commit 0fea51ba53
2 changed files with 97 additions and 5 deletions

View File

@ -11,17 +11,19 @@
namespace App\Jobs\Bank;
use App\Helpers\Bank\Yodlee\Yodlee;
use App\Models\Company;
use App\Libraries\MultiDB;
use Illuminate\Bus\Queueable;
use App\Models\BankIntegration;
use App\Models\BankTransaction;
use App\Models\Company;
use App\Helpers\Bank\Yodlee\Yodlee;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use App\Services\Bank\BankMatchingService;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\Middleware\WithoutOverlapping;
use App\Notifications\Ninja\GenericNinjaAdminNotification;
class ProcessBankTransactions implements ShouldQueue
{
@ -70,6 +72,14 @@ class ProcessBankTransactions implements ShouldQueue
$this->processTransactions();
} catch(\Exception $e) {
nlog("{$this->bank_integration_account_id} - exited abnormally => ". $e->getMessage());
$content = [
"Processing transactions for account: {$this->bank_integration->account->key} failed",
"Exception Details => ",
$e->getMessage(),
];
$this->bank_integration->account->company->notification(new GenericNinjaAdminNotification($content))->ninja();
return;
}
} while ($this->stop_loop);
@ -152,4 +162,15 @@ class ProcessBankTransactions implements ShouldQueue
$this->bank_integration->save();
}
}
public function middleware()
{
return [new WithoutOverlapping($this->bank_integration_account_id)];
}
public function backoff()
{
return [rand(10, 15), rand(30, 40), rand(60, 79), rand(160, 200), rand(3000, 5000)];
}
}

View File

@ -0,0 +1,71 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Notifications\Ninja;
use Illuminate\Notifications\Messages\SlackMessage;
use Illuminate\Notifications\Notification;
class GenericNinjaAdminNotification extends Notification
{
public function __construct(protected array $message_array)
{
}
/**
* Get the notification's delivery channels.
*
* @param mixed $notifiable
* @return array
*/
public function via($notifiable)
{
return ['slack'];
}
/**
* Get the mail representation of the notification.
*
* @param mixed $notifiable
*/
public function toMail($notifiable)
{
}
/**
* Get the array representation of the notification.
*
* @param mixed $notifiable
* @return array
*/
public function toArray($notifiable)
{
return [
//
];
}
public function toSlack($notifiable)
{
$content = '';
foreach($this->message_array as $message) {
$content .= $message . "\n";
}
return (new SlackMessage)
->success()
->from(ctrans('texts.notification_bot'))
->image('https://app.invoiceninja.com/favicon.png')
->content($content);
}
}