Fixes for mailers when attachments are too large

This commit is contained in:
David Bomba 2023-02-01 13:19:35 +11:00
parent 78a69329d4
commit fa1e52b4ca
3 changed files with 29 additions and 15 deletions

View File

@ -176,21 +176,25 @@ class NinjaMailerJob implements ShouldQueue
* this merges a text string with a json object * this merges a text string with a json object
* need to harvest the ->Message property using the following * need to harvest the ->Message property using the following
*/ */
if($e instanceof ClientException) if(stripos($e->getMessage(), 'code 406') || stripos($e->getMessage(), 'code 300'))
{ {
$response = $e->getResponse(); $message = "Either Attachment too large, or recipient has been suppressed.";
$message_body = json_decode($response->getBody()->getContents());
if($message_body && property_exists($message_body, 'Message')){
$message = $message_body->Message;
}
/*Do not retry if this is a postmark specific issue such as invalid recipient. */
$this->fail(); $this->fail();
$this->cleanUpMailers(); $this->cleanUpMailers();
return; return;
// $response = $e->getResponse();
// $message_body = json_decode($response->getBody()->getContents());
// if($message_body && property_exists($message_body, 'Message')){
// $message = $message_body->Message;
// }
/*Do not retry if this is a postmark specific issue such as invalid recipient. */
} }
//only report once, not on all tries //only report once, not on all tries
@ -647,8 +651,9 @@ class NinjaMailerJob implements ShouldQueue
public function failed($exception = null) public function failed($exception = null)
{ {
if($exception)
nlog($exception->getMessage()); config(['queue.failed.driver' => null]);
} }
} }

View File

@ -24,7 +24,6 @@ use Illuminate\Queue\Events\JobProcessing;
use Illuminate\Support\Facades\App; use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Artisan; use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Blade; use Illuminate\Support\Facades\Blade;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Mail; use Illuminate\Support\Facades\Mail;
use Illuminate\Support\Facades\ParallelTesting; use Illuminate\Support\Facades\ParallelTesting;
use Illuminate\Support\Facades\Queue; use Illuminate\Support\Facades\Queue;
@ -52,6 +51,11 @@ class AppServiceProvider extends ServiceProvider
// ); // );
// }); // });
// Model::preventLazyLoading(
// !$this->app->isProduction()
// );
/* Defines the name used in polymorphic tables */
Relation::morphMap([ Relation::morphMap([
'invoices' => Invoice::class, 'invoices' => Invoice::class,
'proposals' => Proposal::class, 'proposals' => Proposal::class,
@ -61,6 +65,7 @@ class AppServiceProvider extends ServiceProvider
return config('ninja.environment') === $environment; return config('ninja.environment') === $environment;
}); });
/* Sets default varchar length */
Schema::defaultStringLength(191); Schema::defaultStringLength(191);
/* Handles setting the correct database with livewire classes */ /* Handles setting the correct database with livewire classes */
@ -75,11 +80,10 @@ class AppServiceProvider extends ServiceProvider
App::forgetInstance('truthsource'); App::forgetInstance('truthsource');
}); });
/* Always init a new instance everytime the container boots */
app()->instance(TruthSource::class, new TruthSource()); app()->instance(TruthSource::class, new TruthSource());
// Model::preventLazyLoading( /* Extension for custom mailers */
// !$this->app->isProduction()
// );
Mail::extend('gmail', function () { Mail::extend('gmail', function () {
return new GmailTransport(); return new GmailTransport();
@ -113,6 +117,10 @@ class AppServiceProvider extends ServiceProvider
return $this; return $this;
}); });
/* Extension for custom mailers */
/* Convenience helper for testing s*/
ParallelTesting::setUpTestDatabase(function ($database, $token) { ParallelTesting::setUpTestDatabase(function ($database, $token) {
Artisan::call('db:seed'); Artisan::call('db:seed');
}); });

View File

@ -64,6 +64,7 @@ class EmailMailer implements ShouldQueue
public function handle(): void public function handle(): void
{ {
throw new \Exception("poopies");
MultiDB::setDb($this->email_service->company->db); MultiDB::setDb($this->email_service->company->db);