From 5f0d9052654e18db46bfd4ecd6488f59fb0fd521 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sun, 20 Nov 2022 11:46:32 +1100 Subject: [PATCH 1/2] Fixes for failed email mailer, edge case where balances may not adjust correctly --- app/Jobs/Mail/NinjaMailerJob.php | 3 --- app/Listeners/Invoice/InvoiceEmailFailedActivity.php | 8 ++++++++ app/Listeners/Invoice/InvoiceFailedEmailNotification.php | 9 +++++++-- app/Repositories/ActivityRepository.php | 2 +- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/app/Jobs/Mail/NinjaMailerJob.php b/app/Jobs/Mail/NinjaMailerJob.php index 9f1674055bbf..7e060e532c85 100644 --- a/app/Jobs/Mail/NinjaMailerJob.php +++ b/app/Jobs/Mail/NinjaMailerJob.php @@ -129,11 +129,8 @@ class NinjaMailerJob implements ShouldQueue LightLogs::create(new EmailSuccess($this->nmo->company->company_key)) ->send(); - // nlog('Using ' . ((int) (memory_get_usage(true) / (1024 * 1024))) . 'MB '); - $this->nmo = null; $this->company = null; - app('queue.worker')->shouldQuit = 1; } catch (\Exception | \RuntimeException | \Google\Service\Exception $e) { diff --git a/app/Listeners/Invoice/InvoiceEmailFailedActivity.php b/app/Listeners/Invoice/InvoiceEmailFailedActivity.php index b46493528fb8..4955cb95f6b5 100644 --- a/app/Listeners/Invoice/InvoiceEmailFailedActivity.php +++ b/app/Listeners/Invoice/InvoiceEmailFailedActivity.php @@ -14,11 +14,19 @@ namespace App\Listeners\Invoice; use App\Libraries\MultiDB; use App\Models\Activity; use App\Repositories\ActivityRepository; +use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; +use Illuminate\Foundation\Bus\Dispatchable; +use Illuminate\Queue\InteractsWithQueue; +use Illuminate\Queue\SerializesModels; use stdClass; class InvoiceEmailFailedActivity implements ShouldQueue { + use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; + + public $delay = 10; + protected $activity_repo; /** diff --git a/app/Listeners/Invoice/InvoiceFailedEmailNotification.php b/app/Listeners/Invoice/InvoiceFailedEmailNotification.php index 92b8d9bef3a7..8ab0e094949f 100644 --- a/app/Listeners/Invoice/InvoiceFailedEmailNotification.php +++ b/app/Listeners/Invoice/InvoiceFailedEmailNotification.php @@ -18,13 +18,18 @@ use App\Libraries\MultiDB; use App\Mail\Admin\EntityFailedSendObject; use App\Notifications\Admin\EntitySentNotification; use App\Utils\Traits\Notifications\UserNotifies; +use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; +use Illuminate\Foundation\Bus\Dispatchable; +use Illuminate\Queue\InteractsWithQueue; +use Illuminate\Queue\SerializesModels; class InvoiceFailedEmailNotification { - use UserNotifies; - public $delay = 5; + use UserNotifies, Dispatchable, InteractsWithQueue, Queueable, SerializesModels; + + public $delay = 10; public function __construct() { diff --git a/app/Repositories/ActivityRepository.php b/app/Repositories/ActivityRepository.php index c20bfb3d346d..7c33c9e6a47f 100644 --- a/app/Repositories/ActivityRepository.php +++ b/app/Repositories/ActivityRepository.php @@ -60,7 +60,7 @@ class ActivityRepository extends BaseRepository $activity->save(); //rate limiter - // $this->createBackup($entity, $activity); + $this->createBackup($entity, $activity); } /** From 86813f91cca90480ccf875a300320bed7e33acf8 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sun, 20 Nov 2022 12:00:04 +1100 Subject: [PATCH 2/2] Adjust when we send certain events after an email failure --- app/Providers/EventServiceProvider.php | 2 +- app/Repositories/ActivityRepository.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.php index 53bb69bbb4ca..cc3a02d52079 100644 --- a/app/Providers/EventServiceProvider.php +++ b/app/Providers/EventServiceProvider.php @@ -451,7 +451,7 @@ class EventServiceProvider extends ServiceProvider PaymentEmailedActivity::class, ], PaymentWasEmailedAndFailed::class => [ - PaymentEmailFailureActivity::class, + // PaymentEmailFailureActivity::class, ], PurchaseOrderWasArchived::class => [ PurchaseOrderArchivedActivity::class, diff --git a/app/Repositories/ActivityRepository.php b/app/Repositories/ActivityRepository.php index 7c33c9e6a47f..b007e1629b90 100644 --- a/app/Repositories/ActivityRepository.php +++ b/app/Repositories/ActivityRepository.php @@ -60,7 +60,7 @@ class ActivityRepository extends BaseRepository $activity->save(); //rate limiter - $this->createBackup($entity, $activity); + $this->createBackup($entity, $activity); } /**