From de8761f5190dfd28876b47bbe6b05a8c0af22256 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Tue, 1 Nov 2022 17:10:05 +1100 Subject: [PATCH] Improve memory handling in jobs --- app/Jobs/Entity/CreateEntityPdf.php | 6 ++++++ app/Jobs/Entity/EmailEntity.php | 3 +++ app/Jobs/Mail/NinjaMailerJob.php | 8 +++++++- app/Jobs/Util/SystemLogger.php | 13 ++++++++++++- 4 files changed, 28 insertions(+), 2 deletions(-) diff --git a/app/Jobs/Entity/CreateEntityPdf.php b/app/Jobs/Entity/CreateEntityPdf.php index 34026a79c5c8..eaff1cb6cb45 100644 --- a/app/Jobs/Entity/CreateEntityPdf.php +++ b/app/Jobs/Entity/CreateEntityPdf.php @@ -218,6 +218,12 @@ class CreateEntityPdf implements ShouldQueue throw new FilePermissionsFailure($e->getMessage()); } } + + $this->invitation = null; + $this->entity = null; + $this->company = null; + $this->client = null; + $this->contact = null; return $file_path; } diff --git a/app/Jobs/Entity/EmailEntity.php b/app/Jobs/Entity/EmailEntity.php index c10a9ed9df8f..ac5a894de312 100644 --- a/app/Jobs/Entity/EmailEntity.php +++ b/app/Jobs/Entity/EmailEntity.php @@ -128,6 +128,9 @@ class EmailEntity implements ShouldQueue $nmo->entity = $this->entity; (new NinjaMailerJob($nmo))->handle(); + + $nmo = null; + $this->invitation = null; } private function resolveEntityString() :string diff --git a/app/Jobs/Mail/NinjaMailerJob.php b/app/Jobs/Mail/NinjaMailerJob.php index b30723a1ff62..f3506741977a 100644 --- a/app/Jobs/Mail/NinjaMailerJob.php +++ b/app/Jobs/Mail/NinjaMailerJob.php @@ -115,6 +115,7 @@ class NinjaMailerJob implements ShouldQueue //send email try { + nlog("trying to send to {$this->nmo->to_user->email} ". now()->toDateTimeString()); nlog("Using mailer => ". $this->mailer); @@ -128,6 +129,8 @@ class NinjaMailerJob implements ShouldQueue LightLogs::create(new EmailSuccess($this->nmo->company->company_key)) ->send(); + $this->nmo = null; + $this->company = null; } catch (\Exception | \RuntimeException | \Google\Service\Exception $e) { @@ -381,7 +384,7 @@ class NinjaMailerJob implements ShouldQueue private function logMailError($errors, $recipient_object) { - SystemLogger::dispatch( + SystemLogger::dispatchSync( $errors, SystemLog::CATEGORY_MAIL, SystemLog::EVENT_MAIL_SEND, @@ -396,6 +399,9 @@ class NinjaMailerJob implements ShouldQueue LightLogs::create($job_failure) ->send(); + + $job_failure = null; + } public function failed($exception = null) diff --git a/app/Jobs/Util/SystemLogger.php b/app/Jobs/Util/SystemLogger.php index daefb4236afc..be7ee1eb5aea 100644 --- a/app/Jobs/Util/SystemLogger.php +++ b/app/Jobs/Util/SystemLogger.php @@ -79,11 +79,22 @@ class SystemLogger implements ShouldQueue if (! $this->log) { nlog('SystemLogger:: no log to store'); - + $this->category_id = null; + $this->event_id = null; + $this->type_id = null; + $this->client = null; + $this->company = null; return; } SystemLog::create($sl); + + $this->log = null; + $this->category_id = null; + $this->event_id = null; + $this->type_id = null; + $this->client = null; + $this->company = null; } public function failed($e)