diff --git a/app/Console/Commands/RecurringCommand.php b/app/Console/Commands/RecurringCommand.php index 628a09b8f548..2bc62d79dee5 100644 --- a/app/Console/Commands/RecurringCommand.php +++ b/app/Console/Commands/RecurringCommand.php @@ -47,6 +47,6 @@ class RecurringCommand extends Command */ public function handle() { - RecurringInvoicesCron::dispatchSync(); + (new RecurringInvoicesCron())->handle(); } } diff --git a/app/Http/Controllers/Auth/LoginController.php b/app/Http/Controllers/Auth/LoginController.php index 9167e8528a2a..9f702bbe3174 100644 --- a/app/Http/Controllers/Auth/LoginController.php +++ b/app/Http/Controllers/Auth/LoginController.php @@ -294,7 +294,7 @@ class LoginController extends BaseController $cu->first()->account->companies->each(function ($company) use ($cu, $request) { if ($company->tokens()->where('is_system', true)->count() == 0) { - CreateCompanyToken::dispatchSync($company, $cu->first()->user, $request->server('HTTP_USER_AGENT')); + (new CreateCompanyToken($company, $cu->first()->user, $request->server('HTTP_USER_AGENT')))->handle(); } }); @@ -474,7 +474,7 @@ class LoginController extends BaseController if (auth()->user()->company_users()->count() != auth()->user()->tokens()->distinct('company_id')->count()) { auth()->user()->companies->each(function ($company) { if (!CompanyToken::where('user_id', auth()->user()->id)->where('company_id', $company->id)->exists()) { - CreateCompanyToken::dispatchSync($company, auth()->user(), 'Google_O_Auth'); + (new CreateCompanyToken($company, auth()->user(), 'Google_O_Auth'))->handle(); } }); } diff --git a/app/Http/Controllers/CompanyController.php b/app/Http/Controllers/CompanyController.php index 5317a46babdf..86fc01c732c7 100644 --- a/app/Http/Controllers/CompanyController.php +++ b/app/Http/Controllers/CompanyController.php @@ -212,8 +212,8 @@ class CompanyController extends BaseController $this->forced_includes = ['company_user']; $company = (new CreateCompany($request->all(), auth()->user()->company()->account))->handle(); - CreateCompanyPaymentTerms::dispatchSync($company, auth()->user()); - CreateCompanyTaskStatuses::dispatchSync($company, auth()->user()); + (new CreateCompanyPaymentTerms($company, auth()->user()))->handle(); + (new CreateCompanyTaskStatuses($company, auth()->user()))->handle(); $company = $this->company_repo->save($request->all(), $company); diff --git a/app/Http/Controllers/SetupController.php b/app/Http/Controllers/SetupController.php index 36493d48f11b..c9ef036af7b7 100644 --- a/app/Http/Controllers/SetupController.php +++ b/app/Http/Controllers/SetupController.php @@ -145,10 +145,10 @@ class SetupController extends Controller /* Create the first account. */ if (Account::count() == 0) { - CreateAccount::dispatchSync($request->all(), $request->getClientIp()); + (new CreateAccount($request->all(), $request->getClientIp()))->handle(); } - VersionCheck::dispatchSync(); + (new VersionCheck())->handle(); $this->buildCache(true); @@ -316,7 +316,7 @@ class SetupController extends Controller $this->buildCache(true); - SchedulerCheck::dispatchSync(); + (new SchedulerCheck())->handle(); return redirect('/'); } diff --git a/app/Jobs/Account/CreateAccount.php b/app/Jobs/Account/CreateAccount.php index 2690d627fb93..9ab7f99cd79f 100644 --- a/app/Jobs/Account/CreateAccount.php +++ b/app/Jobs/Account/CreateAccount.php @@ -97,8 +97,8 @@ class CreateAccount $spaa9f78 = (new CreateUser($this->request, $sp794f3f, $sp035a66, true))->handle(); - CreateCompanyPaymentTerms::dispatchSync($sp035a66, $spaa9f78); - CreateCompanyTaskStatuses::dispatchSync($sp035a66, $spaa9f78); + (new CreateCompanyPaymentTerms($sp035a66, $spaa9f78))->handle(); + (new CreateCompanyTaskStatuses($sp035a66, $spaa9f78))->handle(); if ($spaa9f78) { auth()->login($spaa9f78, false); diff --git a/app/Jobs/Cron/RecurringInvoicesCron.php b/app/Jobs/Cron/RecurringInvoicesCron.php index 5584f5c18628..0923675072f0 100644 --- a/app/Jobs/Cron/RecurringInvoicesCron.php +++ b/app/Jobs/Cron/RecurringInvoicesCron.php @@ -74,7 +74,7 @@ class RecurringInvoicesCron } try { - SendRecurring::dispatchSync($recurring_invoice, $recurring_invoice->company->db); + (new SendRecurring($recurring_invoice, $recurring_invoice->company->db))->handle(); } catch (\Exception $e) { nlog("Unable to sending recurring invoice {$recurring_invoice->id} ".$e->getMessage()); } @@ -114,7 +114,7 @@ class RecurringInvoicesCron } try { - SendRecurring::dispatchSync($recurring_invoice, $recurring_invoice->company->db); + (new SendRecurring($recurring_invoice, $recurring_invoice->company->db))->handle(); } catch (\Exception $e) { nlog("Unable to sending recurring invoice {$recurring_invoice->id} ".$e->getMessage()); } diff --git a/app/Jobs/Entity/EmailEntity.php b/app/Jobs/Entity/EmailEntity.php index cc3cd03ba33a..ce76748a6f6e 100644 --- a/app/Jobs/Entity/EmailEntity.php +++ b/app/Jobs/Entity/EmailEntity.php @@ -126,7 +126,7 @@ class EmailEntity implements ShouldQueue $nmo->reminder_template = $this->reminder_template; $nmo->entity = $this->entity; - NinjaMailerJob::dispatchSync($nmo); + (new NinjaMailerJob($nmo))->handle(); } private function resolveEntityString() :string diff --git a/app/Jobs/Invoice/ZipInvoices.php b/app/Jobs/Invoice/ZipInvoices.php index e3ba20013408..b0b8410b0136 100644 --- a/app/Jobs/Invoice/ZipInvoices.php +++ b/app/Jobs/Invoice/ZipInvoices.php @@ -80,7 +80,7 @@ class ZipInvoices implements ShouldQueue $path = $this->invoices->first()->client->invoice_filepath($invitation); $this->invoices->each(function ($invoice) { - CreateEntityPdf::dispatchSync($invoice->invitations()->first()); + (new CreateEntityPdf($invoice->invitations()->first()))->handle(); }); try { diff --git a/app/Jobs/Mail/NinjaMailerJob.php b/app/Jobs/Mail/NinjaMailerJob.php index 13f06281e112..598156ce711a 100644 --- a/app/Jobs/Mail/NinjaMailerJob.php +++ b/app/Jobs/Mail/NinjaMailerJob.php @@ -101,7 +101,7 @@ class NinjaMailerJob implements ShouldQueue } $this->nmo->mailable->tag($this->company->company_key); - + //send email try { nlog("trying to send to {$this->nmo->to_user->email} ". now()->toDateTimeString()); @@ -117,7 +117,7 @@ class NinjaMailerJob implements ShouldQueue /* Count the amount of emails sent across all the users accounts */ Cache::increment($this->company->account->key); - } catch (\Exception $e) { + } catch (\Exception | \RuntimeException $e) { nlog("error failed with {$e->getMessage()}"); @@ -145,7 +145,7 @@ class NinjaMailerJob implements ShouldQueue $this->entityEmailFailed($message); /* Don't send postmark failures to Sentry */ - if(Ninja::isHosted() && (!$e instanceof ClientException || !$e instanceof \Symfony\Component\Mailer\Exception\HttpTransportException)) + if(Ninja::isHosted() && (!$e instanceof ClientException)) app('sentry')->captureException($e); } } diff --git a/app/Jobs/Ninja/CheckDbStatus.php b/app/Jobs/Ninja/CheckDbStatus.php index 8c782fd5ee57..1fb53b1a123d 100644 --- a/app/Jobs/Ninja/CheckDbStatus.php +++ b/app/Jobs/Ninja/CheckDbStatus.php @@ -39,7 +39,7 @@ class CheckDbStatus implements ShouldQueue */ public function handle() { - DbStatus::dispatchSync('db-ninja-01', 'db.status.db-ninja-01'); - DbStatus::dispatchSync('db-ninja-02', 'db.status.db-ninja-02'); + (new DbStatus('db-ninja-01', 'db.status.db-ninja-01'))->handle(); + (new DbStatus('db-ninja-02', 'db.status.db-ninja-02'))->handle(); } } diff --git a/app/Jobs/Ninja/SendReminders.php b/app/Jobs/Ninja/SendReminders.php index d84c04b3631b..f2d520aac270 100644 --- a/app/Jobs/Ninja/SendReminders.php +++ b/app/Jobs/Ninja/SendReminders.php @@ -214,7 +214,7 @@ class SendReminders implements ShouldQueue if ($this->checkSendSetting($invoice, $template) && $invoice->company->account->hasFeature(Account::FEATURE_EMAIL_TEMPLATES_REMINDERS)) { nlog('firing email'); - EmailEntity::dispatchSync($invitation, $invitation->company, $template); + EmailEntity::dispatch($invitation, $invitation->company, $template)->delay(10); } }); diff --git a/app/Jobs/PurchaseOrder/PurchaseOrderEmail.php b/app/Jobs/PurchaseOrder/PurchaseOrderEmail.php index c49154a09208..aeccc61a723c 100644 --- a/app/Jobs/PurchaseOrder/PurchaseOrderEmail.php +++ b/app/Jobs/PurchaseOrder/PurchaseOrderEmail.php @@ -89,7 +89,7 @@ class PurchaseOrderEmail implements ShouldQueue $nmo->reminder_template = 'purchase_order'; $nmo->entity = $invitation->purchase_order; - NinjaMailerJob::dispatchSync($nmo); + NinjaMailerJob::dispatch($nmo)->delay(5); }); if ($this->purchase_order->invitations->count() >= 1) { diff --git a/app/Jobs/PurchaseOrder/ZipPurchaseOrders.php b/app/Jobs/PurchaseOrder/ZipPurchaseOrders.php index a440e2c1ccb9..73b1f9d399a1 100644 --- a/app/Jobs/PurchaseOrder/ZipPurchaseOrders.php +++ b/app/Jobs/PurchaseOrder/ZipPurchaseOrders.php @@ -82,7 +82,7 @@ class ZipPurchaseOrders implements ShouldQueue $path = $this->purchase_orders->first()->vendor->purchase_order_filepath($invitation); $this->purchase_orders->each(function ($purchase_order) { - CreatePurchaseOrderPdf::dispatchSync($purchase_order->invitations()->first()); + (new CreatePurchaseOrderPdf($purchase_order->invitations()->first()))->handle(); }); try { diff --git a/app/Jobs/Quote/ZipQuotes.php b/app/Jobs/Quote/ZipQuotes.php index c8cf24ed1e8d..a4f9d85883c5 100644 --- a/app/Jobs/Quote/ZipQuotes.php +++ b/app/Jobs/Quote/ZipQuotes.php @@ -80,7 +80,7 @@ class ZipQuotes implements ShouldQueue $path = $this->quotes->first()->client->quote_filepath($invitation); $this->quotes->each(function ($quote) { - CreateEntityPdf::dispatchSync($quote->invitations()->first()); + (new CreateEntityPdf($quote->invitations()->first()))->handle(); }); try { diff --git a/app/Listeners/Quote/ReachWorkflowSettings.php b/app/Listeners/Quote/ReachWorkflowSettings.php index 8d4733fdb83f..16bca41c36c5 100644 --- a/app/Listeners/Quote/ReachWorkflowSettings.php +++ b/app/Listeners/Quote/ReachWorkflowSettings.php @@ -27,6 +27,6 @@ class ReachWorkflowSettings { MultiDB::setDb($event->company->db); - QuoteWorkflowSettings::dispatchSync($event->quote); + (new QuoteWorkflowSettings($event->quote))->handle(); } } diff --git a/app/Mail/VendorTemplateEmail.php b/app/Mail/VendorTemplateEmail.php index 5a9f7e6d2545..94ff1319376d 100644 --- a/app/Mail/VendorTemplateEmail.php +++ b/app/Mail/VendorTemplateEmail.php @@ -130,7 +130,7 @@ class VendorTemplateEmail extends Mailable sleep(2); if(!Storage::disk(config('filesystems.default'))->exists($path)) { - CreatePurchaseOrderPdf::dispatchSync($this->invitation); + (new CreatePurchaseOrderPdf($this->invitation))->handle(); sleep(2); } diff --git a/app/Models/CreditInvitation.php b/app/Models/CreditInvitation.php index ba32dd04f9aa..bcb3daa1d4b8 100644 --- a/app/Models/CreditInvitation.php +++ b/app/Models/CreditInvitation.php @@ -129,8 +129,8 @@ class CreditInvitation extends BaseModel $storage_path = Storage::url($this->credit->client->quote_filepath($this).$this->credit->numberFormatter().'.pdf'); if (! Storage::exists($this->credit->client->credit_filepath($this).$this->credit->numberFormatter().'.pdf')) { - event(new CreditWasUpdated($this, $this->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null))); - CreateEntityPdf::dispatchSync($this); + event(new CreditWasUpdated($this->credit, $this->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null))); + (new CreateEntityPdf($this))->handle(); } return $storage_path; diff --git a/app/Models/QuoteInvitation.php b/app/Models/QuoteInvitation.php index bb6fce43867a..7c2378ea2580 100644 --- a/app/Models/QuoteInvitation.php +++ b/app/Models/QuoteInvitation.php @@ -134,7 +134,7 @@ class QuoteInvitation extends BaseModel if (! Storage::exists($this->quote->client->quote_filepath($this).$this->quote->numberFormatter().'.pdf')) { event(new QuoteWasUpdated($this->quote, $this->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null))); - CreateEntityPdf::dispatchSync($this); + (new CreateEntityPdf($this))->handle(); } return $storage_path; diff --git a/app/Services/Credit/CreditService.php b/app/Services/Credit/CreditService.php index ec43ceed2403..eeac8f404766 100644 --- a/app/Services/Credit/CreditService.php +++ b/app/Services/Credit/CreditService.php @@ -196,7 +196,7 @@ class CreditService try { if ($force) { $this->credit->invitations->each(function ($invitation) { - CreateEntityPdf::dispatchSync($invitation); + (new CreateEntityPdf($invitation))->handle(); }); return $this; @@ -243,7 +243,7 @@ class CreditService public function deletePdf() { $this->credit->invitations->each(function ($invitation) { - UnlinkFile::dispatchSync(config('filesystems.default'), $this->credit->client->credit_filepath($invitation).$this->credit->numberFormatter().'.pdf'); + (new UnlinkFile(config('filesystems.default'), $this->credit->client->credit_filepath($invitation).$this->credit->numberFormatter().'.pdf'))->handle(); }); return $this; diff --git a/app/Services/Invoice/InvoiceService.php b/app/Services/Invoice/InvoiceService.php index 2af53ce6b08a..c20594a03e3a 100644 --- a/app/Services/Invoice/InvoiceService.php +++ b/app/Services/Invoice/InvoiceService.php @@ -421,7 +421,6 @@ class InvoiceService try { if ($force) { $this->invoice->invitations->each(function ($invitation) { - // CreateEntityPdf::dispatchSync($invitation); (new CreateEntityPdf($invitation))->handle(); }); @@ -562,7 +561,6 @@ class InvoiceService { if ($this->invoice->company->track_inventory) { (new AdjustProductInventory($this->invoice->company, $this->invoice, $old_invoice))->handle(); - // AdjustProductInventory::dispatchSync($this->invoice->company, $this->invoice, $old_invoice); } return $this; diff --git a/app/Services/Invoice/SendEmail.php b/app/Services/Invoice/SendEmail.php index 10a35479c460..55f9c534fad8 100644 --- a/app/Services/Invoice/SendEmail.php +++ b/app/Services/Invoice/SendEmail.php @@ -45,7 +45,7 @@ class SendEmail extends AbstractService $this->invoice->invitations->each(function ($invitation) { if (! $invitation->contact->trashed() && $invitation->contact->email) { - EmailEntity::dispatchSync($invitation, $invitation->company, $this->reminder_template); + EmailEntity::dispatch($invitation, $invitation->company, $this->reminder_template)->delay(10); } }); } diff --git a/app/Services/Payment/SendEmail.php b/app/Services/Payment/SendEmail.php index 87ff586edcdf..598fd92f3dd9 100644 --- a/app/Services/Payment/SendEmail.php +++ b/app/Services/Payment/SendEmail.php @@ -36,10 +36,7 @@ class SendEmail $this->payment->client->contacts->each(function ($contact) { if ($contact->email) { - // dispatchSync always returns 0, in this case we can handle it without returning false; - return EmailPayment::dispatchSync($this->payment, $this->payment->company, $contact); - // return false; - //11-01-2021 only send payment receipt to the first contact + EmailPayment::dispatch($this->payment, $this->payment->company, $contact); } }); } diff --git a/app/Services/Quote/QuoteService.php b/app/Services/Quote/QuoteService.php index 62414cec3377..8a8174c3ea4c 100644 --- a/app/Services/Quote/QuoteService.php +++ b/app/Services/Quote/QuoteService.php @@ -136,7 +136,7 @@ class QuoteService try { if ($force) { $this->quote->invitations->each(function ($invitation) { - CreateEntityPdf::dispatchSync($invitation); + (new CreateEntityPdf($invitation))->handle(); }); return $this; @@ -225,7 +225,7 @@ class QuoteService public function deletePdf() { $this->quote->invitations->each(function ($invitation) { - UnlinkFile::dispatchSync(config('filesystems.default'), $this->quote->client->quote_filepath($invitation).$this->quote->numberFormatter().'.pdf'); + (new UnlinkFile(config('filesystems.default'), $this->quote->client->quote_filepath($invitation).$this->quote->numberFormatter().'.pdf'))->handle(); }); return $this;