mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
Refactor to remove dispatchSync from code path
This commit is contained in:
parent
a321153a5a
commit
7ac4786bff
@ -47,6 +47,6 @@ class RecurringCommand extends Command
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
RecurringInvoicesCron::dispatchSync();
|
||||
(new RecurringInvoicesCron())->handle();
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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('/');
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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());
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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 {
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -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) {
|
||||
|
@ -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 {
|
||||
|
@ -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 {
|
||||
|
@ -27,6 +27,6 @@ class ReachWorkflowSettings
|
||||
{
|
||||
MultiDB::setDb($event->company->db);
|
||||
|
||||
QuoteWorkflowSettings::dispatchSync($event->quote);
|
||||
(new QuoteWorkflowSettings($event->quote))->handle();
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user