From e55de0fb1b9e52cc76b6271fc29227e7a5d2a54f Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sun, 22 Nov 2020 22:14:49 +1100 Subject: [PATCH] Change default queue to database --- app/Jobs/Entity/CreateEntityPdf.php | 13 +++++++++-- app/Jobs/Mail/BaseMailerJob.php | 6 +++++ app/Jobs/Util/WebhookHandler.php | 22 ++++++++++++------- app/Listeners/Invoice/InvoicePaidActivity.php | 9 ++++++-- config/queue.php | 2 +- 5 files changed, 39 insertions(+), 13 deletions(-) diff --git a/app/Jobs/Entity/CreateEntityPdf.php b/app/Jobs/Entity/CreateEntityPdf.php index fca7262c0ad0..a3847da9fe4c 100644 --- a/app/Jobs/Entity/CreateEntityPdf.php +++ b/app/Jobs/Entity/CreateEntityPdf.php @@ -162,9 +162,18 @@ class CreateEntityPdf implements ShouldQueue //todo - move this to the client creation stage so we don't keep hitting this unnecessarily Storage::makeDirectory($path, 0775); - $pdf = $this->makePdf(null, null, $maker->getCompiledHTML(true)); + $pdf = null; - $instance = Storage::disk($this->disk)->put($file_path, $pdf); + try { + + $pdf = $this->makePdf(null, null, $maker->getCompiledHTML(true)); + } + catch(\Exception $e) { + info(print_r($e->getMessage(),1)); + } + + if($pdf) + $instance = Storage::disk($this->disk)->put($file_path, $pdf); return $file_path; } diff --git a/app/Jobs/Mail/BaseMailerJob.php b/app/Jobs/Mail/BaseMailerJob.php index af2c4afc1bf4..a938086e133b 100644 --- a/app/Jobs/Mail/BaseMailerJob.php +++ b/app/Jobs/Mail/BaseMailerJob.php @@ -35,6 +35,12 @@ class BaseMailerJob implements ShouldQueue { use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; + public $tries = 5; //number of retries + + public $backoff = 5; //seconds to wait until retry + + public $deleteWhenMissingModels = true; + public function setMailDriver() { App::forgetInstance('translator'); diff --git a/app/Jobs/Util/WebhookHandler.php b/app/Jobs/Util/WebhookHandler.php index db3b55a288e5..11ec72cff38e 100644 --- a/app/Jobs/Util/WebhookHandler.php +++ b/app/Jobs/Util/WebhookHandler.php @@ -32,6 +32,14 @@ class WebhookHandler implements ShouldQueue private $event_id; private $company; + + public $tries = 5; //number of retries + + public $backoff = 5; //seconds to wait until retry + + public $deleteWhenMissingModels = true; + + /** * Create a new job instance. * @@ -50,28 +58,26 @@ class WebhookHandler implements ShouldQueue * * @return bool */ - public function handle() :bool + public function handle() {//todo set multidb here MultiDB::setDb($this->company->db); - if (! $this->company || $this->company->is_disabled) { + if (! $this->company || $this->company->is_disabled) return true; - } + $subscriptions = Webhook::where('company_id', $this->company->id) ->where('event_id', $this->event_id) ->get(); - if (! $subscriptions || $subscriptions->count() == 0) { - return true; - } - + if (! $subscriptions || $subscriptions->count() == 0) + return; + $subscriptions->each(function ($subscription) { $this->process($subscription); }); - return true; } private function process($subscription) diff --git a/app/Listeners/Invoice/InvoicePaidActivity.php b/app/Listeners/Invoice/InvoicePaidActivity.php index 5ab2759764c2..c90bf32afbb5 100644 --- a/app/Listeners/Invoice/InvoicePaidActivity.php +++ b/app/Listeners/Invoice/InvoicePaidActivity.php @@ -46,8 +46,6 @@ class InvoicePaidActivity implements ShouldQueue { MultiDB::setDb($event->company->db); - $event->invoice->service()->touchPdf(); - $fields = new stdClass; $fields->invoice_id = $event->invoice->id; @@ -56,5 +54,12 @@ class InvoicePaidActivity implements ShouldQueue $fields->activity_type_id = Activity::PAID_INVOICE; $this->activity_repo->save($fields, $event->invoice, $event->event_vars); + + try { + $event->invoice->service()->touchPdf(); + } + catch(\Exception $e){ + info(print_r($e->getMessage(),1)); + } } } diff --git a/config/queue.php b/config/queue.php index 00b76d651812..b706b148f30c 100644 --- a/config/queue.php +++ b/config/queue.php @@ -13,7 +13,7 @@ return [ | */ - 'default' => env('QUEUE_CONNECTION', 'sync'), + 'default' => env('QUEUE_CONNECTION', 'database'), /* |--------------------------------------------------------------------------