Improve memory handling in jobs

This commit is contained in:
David Bomba 2022-11-01 17:10:05 +11:00
parent b7b49441f6
commit de8761f519
4 changed files with 28 additions and 2 deletions

View File

@ -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;
}

View File

@ -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

View File

@ -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)

View File

@ -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)