Reducing the quantity of jobs dispatched

This commit is contained in:
David Bomba 2023-02-17 19:58:30 +11:00
parent 681fc47a68
commit 1de91c9e33
28 changed files with 45 additions and 99 deletions

View File

@ -1 +1 @@
5.5.70 5.5.71

View File

@ -73,19 +73,15 @@ class CreateEntityPdf implements ShouldQueue
$this->invitation = $invitation; $this->invitation = $invitation;
if ($invitation instanceof InvoiceInvitation) { if ($invitation instanceof InvoiceInvitation) {
// $invitation->load('contact.client.company','invoice.client','invoice.user.account');
$this->entity = $invitation->invoice; $this->entity = $invitation->invoice;
$this->entity_string = 'invoice'; $this->entity_string = 'invoice';
} elseif ($invitation instanceof QuoteInvitation) { } elseif ($invitation instanceof QuoteInvitation) {
// $invitation->load('contact.client.company','quote.client','quote.user.account');
$this->entity = $invitation->quote; $this->entity = $invitation->quote;
$this->entity_string = 'quote'; $this->entity_string = 'quote';
} elseif ($invitation instanceof CreditInvitation) { } elseif ($invitation instanceof CreditInvitation) {
// $invitation->load('contact.client.company','credit.client','credit.user.account');
$this->entity = $invitation->credit; $this->entity = $invitation->credit;
$this->entity_string = 'credit'; $this->entity_string = 'credit';
} elseif ($invitation instanceof RecurringInvoiceInvitation) { } elseif ($invitation instanceof RecurringInvoiceInvitation) {
// $invitation->load('contact.client.company','recurring_invoice');
$this->entity = $invitation->recurring_invoice; $this->entity = $invitation->recurring_invoice;
$this->entity_string = 'recurring_invoice'; $this->entity_string = 'recurring_invoice';
} }

View File

@ -19,25 +19,16 @@ use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\Middleware\WithoutOverlapping;
use Illuminate\Queue\SerializesModels; use Illuminate\Queue\SerializesModels;
class ClientLedgerBalanceUpdate implements ShouldQueue class ClientLedgerBalanceUpdate implements ShouldQueue
{ {
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public $tries = 1; public $tries = 1;
public $company;
public $client;
public $deleteWhenMissingModels = true; public $deleteWhenMissingModels = true;
public function __construct(public Company $company, public Client $client)
public function __construct(Company $company, Client $client) {}
{
$this->company = $company;
$this->client = $client;
}
/** /**
* Execute the job. * Execute the job.
@ -71,4 +62,11 @@ class ClientLedgerBalanceUpdate implements ShouldQueue
$company_ledger->save(); $company_ledger->save();
}); });
} }
public function middleware()
{
return [(new WithoutOverlapping($this->client->id))->dontRelease()];
}
} }

View File

@ -56,9 +56,5 @@ class QuoteWorkflowSettings implements ShouldQueue
$this->quote->service()->sendEmail($invitation->contact); $this->quote->service()->sendEmail($invitation->contact);
}); });
} }
// if ($this->client->getSetting('auto_archive_quote')) {
// $this->base_repository->archive($this->quote);
// }
} }
} }

View File

@ -24,6 +24,8 @@ class CreditCreatedNotification implements ShouldQueue
{ {
use UserNotifies; use UserNotifies;
public $delay = 10;
public function __construct() public function __construct()
{ {
} }
@ -64,10 +66,8 @@ class CreditCreatedNotification implements ShouldQueue
$nmo->to_user = $user; $nmo->to_user = $user;
NinjaMailerJob::dispatch($nmo); (new NinjaMailerJob($nmo))->handle();
/* This prevents more than one notification being sent */
// $first_notification_sent = false;
} }
/* Override the methods in the Notification Class */ /* Override the methods in the Notification Class */

View File

@ -62,14 +62,10 @@ class CreditEmailedNotification implements ShouldQueue
$nmo->to_user = $user; $nmo->to_user = $user;
NinjaMailerJob::dispatch($nmo); (new NinjaMailerJob($nmo))->handle();
// $first_notification_sent = false;
} }
// $notification->method = $methods;
// $user->notify($notification);
} }
} }
} }

View File

@ -24,7 +24,7 @@ class InvoiceCreatedNotification implements ShouldQueue
{ {
use UserNotifies; use UserNotifies;
public $delay = 5; public $delay = 7;
public function __construct() public function __construct()
{ {
@ -70,7 +70,7 @@ class InvoiceCreatedNotification implements ShouldQueue
$nmo->to_user = $user; $nmo->to_user = $user;
NinjaMailerJob::dispatch($nmo); (new NinjaMailerJob($nmo))->handle();
/* This prevents more than one notification being sent */ /* This prevents more than one notification being sent */
$first_notification_sent = false; $first_notification_sent = false;

View File

@ -24,7 +24,7 @@ class InvoiceEmailedNotification implements ShouldQueue
{ {
use UserNotifies; use UserNotifies;
public $delay = 5; public $delay = 10;
public function __construct() public function __construct()
{ {
@ -68,7 +68,7 @@ class InvoiceEmailedNotification implements ShouldQueue
$nmo->to_user = $user; $nmo->to_user = $user;
NinjaMailerJob::dispatch($nmo); (new NinjaMailerJob($nmo))->handle();
/* This prevents more than one notification being sent */ /* This prevents more than one notification being sent */
$first_notification_sent = false; $first_notification_sent = false;

View File

@ -26,6 +26,8 @@ class InvoiceFailedEmailNotification
{ {
use UserNotifies, Dispatchable, InteractsWithQueue, Queueable, SerializesModels; use UserNotifies, Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public $delay = 7;
public function __construct() public function __construct()
{ {
} }
@ -60,7 +62,7 @@ class InvoiceFailedEmailNotification
$nmo->to_user = $user; $nmo->to_user = $user;
NinjaMailerJob::dispatch($nmo); (new NinjaMailerJob($nmo))->handle();
$first_notification_sent = false; $first_notification_sent = false;
} }

View File

@ -57,10 +57,5 @@ class InvoicePaidActivity implements ShouldQueue
$event->invoice->subscription->service()->planPaid($event->invoice); $event->invoice->subscription->service()->planPaid($event->invoice);
} }
// try {
// $event->invoice->service()->touchPdf();
// } catch (\Exception $e) {
// nlog(print_r($e->getMessage(), 1));
// }
} }
} }

View File

@ -74,7 +74,7 @@ class InvitationViewedListener implements ShouldQueue
unset($methods[$key]); unset($methods[$key]);
$nmo->to_user = $company_user->user; $nmo->to_user = $company_user->user;
NinjaMailerJob::dispatch($nmo); (new NinjaMailerJob($nmo))->handle();
} }
} }
} }

View File

@ -39,7 +39,6 @@ class PaymentEmailedActivity implements ShouldQueue
public function handle($event) public function handle($event)
{ {
MultiDB::setDb($event->company->db); MultiDB::setDb($event->company->db);
$payment = $event->payment; $payment = $event->payment;
} }
} }

View File

@ -24,7 +24,7 @@ class PaymentNotification implements ShouldQueue
{ {
use UserNotifies; use UserNotifies;
public $delay = 5; public $delay = 20;
/** /**
* Create the event listener. * Create the event listener.
@ -75,7 +75,7 @@ class PaymentNotification implements ShouldQueue
$nmo->to_user = $user; $nmo->to_user = $user;
NinjaMailerJob::dispatch($nmo); (new NinjaMailerJob($nmo))->handle();
} }
} }

View File

@ -64,7 +64,7 @@ class PurchaseOrderAcceptedListener implements ShouldQueue
$nmo->to_user = $user; $nmo->to_user = $user;
NinjaMailerJob::dispatch($nmo); (new NinjaMailerJob($nmo))->handle();
/* This prevents more than one notification being sent */ /* This prevents more than one notification being sent */
$first_notification_sent = false; $first_notification_sent = false;

View File

@ -25,6 +25,8 @@ class PurchaseOrderCreatedListener implements ShouldQueue
{ {
use UserNotifies; use UserNotifies;
public $delay = 7;
public function __construct() public function __construct()
{ {
} }
@ -69,7 +71,7 @@ class PurchaseOrderCreatedListener implements ShouldQueue
$nmo->to_user = $user; $nmo->to_user = $user;
NinjaMailerJob::dispatch($nmo); (new NinjaMailerJob($nmo))->handle();
/* This prevents more than one notification being sent */ /* This prevents more than one notification being sent */
$first_notification_sent = false; $first_notification_sent = false;

View File

@ -68,7 +68,7 @@ class PurchaseOrderEmailedNotification implements ShouldQueue
$nmo->to_user = $user; $nmo->to_user = $user;
NinjaMailerJob::dispatch($nmo); (new NinjaMailerJob($nmo))->handle();
/* This prevents more than one notification being sent */ /* This prevents more than one notification being sent */
$first_notification_sent = false; $first_notification_sent = false;

View File

@ -23,7 +23,7 @@ class QuoteApprovedNotification implements ShouldQueue
{ {
use UserNotifies; use UserNotifies;
public $delay = 5; public $delay = 8;
public function __construct() public function __construct()
{ {
@ -66,7 +66,7 @@ class QuoteApprovedNotification implements ShouldQueue
$nmo->to_user = $user; $nmo->to_user = $user;
NinjaMailerJob::dispatch($nmo); (new NinjaMailerJob($nmo))->handle();
/* This prevents more than one notification being sent */ /* This prevents more than one notification being sent */
$first_notification_sent = false; $first_notification_sent = false;

View File

@ -70,7 +70,7 @@ class QuoteCreatedNotification implements ShouldQueue
$nmo->to_user = $user; $nmo->to_user = $user;
NinjaMailerJob::dispatch($nmo); (new NinjaMailerJob($nmo))->handle();
/* This prevents more than one notification being sent */ /* This prevents more than one notification being sent */
$first_notification_sent = false; $first_notification_sent = false;

View File

@ -54,8 +54,6 @@ class QuoteEmailedNotification implements ShouldQueue
foreach ($event->invitation->company->company_users as $company_user) { foreach ($event->invitation->company->company_users as $company_user) {
$user = $company_user->user; $user = $company_user->user;
// $notification = new EntitySentNotification($event->invitation, 'quote');
$methods = $this->findUserNotificationTypes($event->invitation, $company_user, 'quote', ['all_notifications', 'quote_sent', 'quote_sent_all', 'quote_sent_user']); $methods = $this->findUserNotificationTypes($event->invitation, $company_user, 'quote', ['all_notifications', 'quote_sent', 'quote_sent_all', 'quote_sent_user']);
if (($key = array_search('mail', $methods)) !== false) { if (($key = array_search('mail', $methods)) !== false) {
@ -63,14 +61,10 @@ class QuoteEmailedNotification implements ShouldQueue
$nmo->to_user = $user; $nmo->to_user = $user;
NinjaMailerJob::dispatch($nmo); (new NinjaMailerJob($nmo))->handle();
// $first_notification_sent = false;
} }
// $notification->method = $methods;
// $user->notify($notification);
} }
} }
} }

View File

@ -16,6 +16,7 @@ use App\Utils\Ninja;
use App\Utils\Number; use App\Utils\Number;
use Illuminate\Support\Facades\App; use Illuminate\Support\Facades\App;
use stdClass; use stdClass;
use App\Models\Payment;
class EntityPaidObject class EntityPaidObject
{ {
@ -29,7 +30,7 @@ class EntityPaidObject
public $settings; public $settings;
public function __construct($payment) public function __construct(public Payment $payment)
{ {
$this->payment = $payment; $this->payment = $payment;
$this->company = $payment->company; $this->company = $payment->company;

View File

@ -323,7 +323,7 @@ class PaymentEmailEngine extends BaseEmailEngine
$invoice_list = '<br><br>'; $invoice_list = '<br><br>';
foreach ($this->payment->invoices as $invoice) { foreach ($this->payment->invoices as $invoice) {
$invoice_list .= ctrans('texts.invoice_number_short')." {$invoice->number} - ".Number::formatMoney($invoice->pivot->amount, $this->client).'<br>'; $invoice_list .= ctrans('texts.invoice_number_short')." {$invoice->number} ".Number::formatMoney($invoice->pivot->amount, $this->client).'<br>';
} }
return $invoice_list; return $invoice_list;

View File

@ -74,6 +74,8 @@ class CompanyGateway extends BaseModel
// const TYPE_WEPAY = 309; // const TYPE_WEPAY = 309;
// const TYPE_PAYFAST = 310; // const TYPE_PAYFAST = 310;
// const TYPE_PAYTRACE = 311; // const TYPE_PAYTRACE = 311;
// const TYPE_MOLLIE = 312;
// const TYPE_EWAY = 313;
// const TYPE_FORTE = 314; // const TYPE_FORTE = 314;
public $gateway_consts = [ public $gateway_consts = [
@ -87,6 +89,8 @@ class CompanyGateway extends BaseModel
'8fdeed552015b3c7b44ed6c8ebd9e992' => 309, '8fdeed552015b3c7b44ed6c8ebd9e992' => 309,
'd6814fc83f45d2935e7777071e629ef9' => 310, 'd6814fc83f45d2935e7777071e629ef9' => 310,
'bbd736b3254b0aabed6ad7fda1298c88' => 311, 'bbd736b3254b0aabed6ad7fda1298c88' => 311,
'1bd651fb213ca0c9d66ae3c336dc77e7' => 312,
'944c20175bbe6b9972c05bcfe294c2c7' => 313,
'kivcvjexxvdiyqtj3mju5d6yhpeht2xs' => 314, 'kivcvjexxvdiyqtj3mju5d6yhpeht2xs' => 314,
'65faab2ab6e3223dbe848b1686490baz' => 320, '65faab2ab6e3223dbe848b1686490baz' => 320,
'b9886f9257f0c6ee7c302f1c74475f6c' => 321, 'b9886f9257f0c6ee7c302f1c74475f6c' => 321,

View File

@ -11,7 +11,6 @@
namespace App\Models; namespace App\Models;
use App\Events\Credit\CreditWasUpdated;
use App\Jobs\Entity\CreateEntityPdf; use App\Jobs\Entity\CreateEntityPdf;
use App\Utils\Ninja; use App\Utils\Ninja;
use App\Utils\Traits\Inviteable; use App\Utils\Traits\Inviteable;
@ -44,38 +43,6 @@ class CreditInvitation extends BaseModel
return self::class; return self::class;
} }
// public function getSignatureDateAttribute($value)
// {
// if (!$value) {
// return (new Carbon($value))->format('Y-m-d');
// }
// return $value;
// }
// public function getSentDateAttribute($value)
// {
// if (!$value) {
// return (new Carbon($value))->format('Y-m-d');
// }
// return $value;
// }
// public function getViewedDateAttribute($value)
// {
// if (!$value) {
// return (new Carbon($value))->format('Y-m-d');
// }
// return $value;
// }
// public function getOpenedDateAttribute($value)
// {
// if (!$value) {
// return (new Carbon($value))->format('Y-m-d');
// }
// return $value;
// }
public function entityType() public function entityType()
{ {
return Credit::class; return Credit::class;
@ -129,7 +96,6 @@ class CreditInvitation extends BaseModel
$storage_path = Storage::url($this->credit->client->quote_filepath($this).$this->credit->numberFormatter().'.pdf'); $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')) { if (! Storage::exists($this->credit->client->credit_filepath($this).$this->credit->numberFormatter().'.pdf')) {
event(new CreditWasUpdated($this->credit, $this->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null)));
(new CreateEntityPdf($this))->handle(); (new CreateEntityPdf($this))->handle();
} }

View File

@ -101,7 +101,6 @@ class QuoteInvitation extends BaseModel
$storage_path = Storage::url($this->quote->client->quote_filepath($this).$this->quote->numberFormatter().'.pdf'); $storage_path = Storage::url($this->quote->client->quote_filepath($this).$this->quote->numberFormatter().'.pdf');
if (! Storage::exists($this->quote->client->quote_filepath($this).$this->quote->numberFormatter().'.pdf')) { 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)));
(new CreateEntityPdf($this))->handle(); (new CreateEntityPdf($this))->handle();
} }

View File

@ -407,12 +407,10 @@ class EventServiceProvider extends ServiceProvider
], ],
InvoiceWasUpdated::class => [ InvoiceWasUpdated::class => [
UpdateInvoiceActivity::class, UpdateInvoiceActivity::class,
CreateInvoicePdf::class,
], ],
InvoiceWasCreated::class => [ InvoiceWasCreated::class => [
CreateInvoiceActivity::class, CreateInvoiceActivity::class,
InvoiceCreatedNotification::class, InvoiceCreatedNotification::class,
// CreateInvoicePdf::class,
], ],
InvoiceWasPaid::class => [ InvoiceWasPaid::class => [
InvoicePaidActivity::class, InvoicePaidActivity::class,
@ -451,7 +449,7 @@ class EventServiceProvider extends ServiceProvider
InvitationViewedListener::class, InvitationViewedListener::class,
], ],
PaymentWasEmailed::class => [ PaymentWasEmailed::class => [
PaymentEmailedActivity::class, // PaymentEmailedActivity::class,
], ],
PaymentWasEmailedAndFailed::class => [ PaymentWasEmailedAndFailed::class => [
// PaymentEmailFailureActivity::class, // PaymentEmailFailureActivity::class,

View File

@ -23,7 +23,6 @@ use Illuminate\Queue\SerializesModels;
class BankMatchingService implements ShouldQueue class BankMatchingService implements ShouldQueue
{ {
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public function __construct(public $company_id, public $db) public function __construct(public $company_id, public $db)
{ {
} }

View File

@ -137,6 +137,7 @@ class ApplyPayment
->updateBalance($this->amount_applied * -1) ->updateBalance($this->amount_applied * -1)
->updatePaidToDate($this->amount_applied) ->updatePaidToDate($this->amount_applied)
->updateStatus() ->updateStatus()
->touchPdf()
->save(); ->save();
$this->credit $this->credit

View File

@ -14,8 +14,8 @@ return [
'require_https' => env('REQUIRE_HTTPS', true), 'require_https' => env('REQUIRE_HTTPS', true),
'app_url' => rtrim(env('APP_URL', ''), '/'), 'app_url' => rtrim(env('APP_URL', ''), '/'),
'app_domain' => env('APP_DOMAIN', 'invoicing.co'), 'app_domain' => env('APP_DOMAIN', 'invoicing.co'),
'app_version' => '5.5.70', 'app_version' => '5.5.71',
'app_tag' => '5.5.70', 'app_tag' => '5.5.71',
'minimum_client_version' => '5.0.16', 'minimum_client_version' => '5.0.16',
'terms_version' => '1.0.1', 'terms_version' => '1.0.1',
'api_secret' => env('API_SECRET', ''), 'api_secret' => env('API_SECRET', ''),