Delay events slightly to prevent race conditions

This commit is contained in:
David Bomba 2021-12-17 18:57:26 +11:00
parent cda41fbd46
commit c76cb3eb7c
34 changed files with 79 additions and 10 deletions

View File

@ -21,6 +21,8 @@ class CreateInvoiceActivity implements ShouldQueue
{ {
protected $activity_repo; protected $activity_repo;
public $delay = 5;
/** /**
* Create the event listener. * Create the event listener.
* *

View File

@ -21,6 +21,8 @@ class InvoiceArchivedActivity implements ShouldQueue
{ {
protected $activity_repo; protected $activity_repo;
public $delay = 5;
/** /**
* Create the event listener. * Create the event listener.
* *

View File

@ -21,6 +21,8 @@ class InvoiceCancelledActivity implements ShouldQueue
{ {
protected $activity_repo; protected $activity_repo;
public $delay = 5;
/** /**
* Create the event listener. * Create the event listener.
* *

View File

@ -24,6 +24,8 @@ class InvoiceCreatedNotification implements ShouldQueue
{ {
use UserNotifies; use UserNotifies;
public $delay = 5;
public function __construct() public function __construct()
{ {
} }

View File

@ -21,6 +21,8 @@ class InvoiceDeletedActivity implements ShouldQueue
{ {
protected $activity_repo; protected $activity_repo;
public $delay = 5;
/** /**
* Create the event listener. * Create the event listener.
* *

View File

@ -21,6 +21,8 @@ class InvoiceEmailActivity implements ShouldQueue
{ {
protected $activity_repo; protected $activity_repo;
public $delay = 5;
/** /**
* Create the event listener. * Create the event listener.
* *

View File

@ -21,6 +21,8 @@ class InvoiceEmailFailedActivity implements ShouldQueue
{ {
protected $activity_repo; protected $activity_repo;
public $delay = 5;
/** /**
* Create the event listener. * Create the event listener.
* *

View File

@ -24,6 +24,8 @@ class InvoiceEmailedNotification implements ShouldQueue
{ {
use UserNotifies; use UserNotifies;
public $delay = 5;
public function __construct() public function __construct()
{ {
} }

View File

@ -24,6 +24,8 @@ class InvoiceFailedEmailNotification
{ {
use UserNotifies; use UserNotifies;
public $delay = 5;
public function __construct() public function __construct()
{ {
} }

View File

@ -21,6 +21,8 @@ class InvoicePaidActivity implements ShouldQueue
{ {
protected $activity_repo; protected $activity_repo;
public $delay = 5;
/** /**
* Create the event listener. * Create the event listener.
* *

View File

@ -20,6 +20,8 @@ class InvoiceReminderEmailActivity implements ShouldQueue
{ {
protected $activity_repo; protected $activity_repo;
public $delay = 5;
/** /**
* Create the event listener. * Create the event listener.
* *

View File

@ -21,6 +21,8 @@ class InvoiceRestoredActivity implements ShouldQueue
{ {
protected $activity_repo; protected $activity_repo;
public $delay = 5;
/** /**
* Create the event listener. * Create the event listener.
* *

View File

@ -21,6 +21,8 @@ class InvoiceReversedActivity implements ShouldQueue
{ {
protected $activity_repo; protected $activity_repo;
public $delay = 5;
/** /**
* Create the event listener. * Create the event listener.
* *

View File

@ -21,6 +21,8 @@ class InvoiceViewedActivity implements ShouldQueue
{ {
protected $activity_repo; protected $activity_repo;
public $delay = 5;
/** /**
* Create the event listener. * Create the event listener.
* *

View File

@ -21,6 +21,8 @@ class UpdateInvoiceActivity implements ShouldQueue
{ {
protected $activity_repo; protected $activity_repo;
public $delay = 5;
/** /**
* Create the event listener. * Create the event listener.
* *

View File

@ -16,6 +16,9 @@ use Illuminate\Contracts\Queue\ShouldQueue;
class UpdateInvoiceInvitations implements ShouldQueue class UpdateInvoiceInvitations implements ShouldQueue
{ {
public $delay = 5;
/** /**
* Create the event listener. * Create the event listener.
* *

View File

@ -19,6 +19,8 @@ class PaymentEmailFailureActivity implements ShouldQueue
{ {
use UserNotifies; use UserNotifies;
public $delay = 5;
/** /**
* Create the event listener. * Create the event listener.
* *

View File

@ -17,6 +17,8 @@ use Illuminate\Contracts\Queue\ShouldQueue;
class PaymentEmailedActivity implements ShouldQueue class PaymentEmailedActivity implements ShouldQueue
{ {
public $delay = 5;
use UserNotifies; use UserNotifies;
/** /**

View File

@ -26,6 +26,9 @@ class PaymentNotification implements ShouldQueue
{ {
use UserNotifies; use UserNotifies;
public $delay = 5;
/** /**
* Create the event listener. * Create the event listener.
* *

View File

@ -21,6 +21,8 @@ class PaymentRestoredActivity implements ShouldQueue
{ {
protected $activity_repo; protected $activity_repo;
public $delay = 5;
/** /**
* Create the event listener. * Create the event listener.
* *

View File

@ -21,6 +21,8 @@ class CreateQuoteInvitation implements ShouldQueue
{ {
use MakesHash; use MakesHash;
public $delay = 5;
/** /**
* Handle the event. * Handle the event.
* *

View File

@ -21,6 +21,8 @@ class QuoteApprovedActivity implements ShouldQueue
{ {
protected $activity_repo; protected $activity_repo;
public $delay = 5;
/** /**
* Create the event listener. * Create the event listener.
* *

View File

@ -25,6 +25,8 @@ class QuoteApprovedNotification implements ShouldQueue
{ {
use UserNotifies; use UserNotifies;
public $delay = 5;
public function __construct() public function __construct()
{ {
} }

View File

@ -18,7 +18,8 @@ use Illuminate\Contracts\Queue\ShouldQueue;
class QuoteApprovedWebhook implements ShouldQueue class QuoteApprovedWebhook implements ShouldQueue
{ {
public $delay = 5;
public function __construct() public function __construct()
{ {
} }

View File

@ -19,6 +19,8 @@ use stdClass;
class QuoteArchivedActivity implements ShouldQueue class QuoteArchivedActivity implements ShouldQueue
{ {
public $delay = 5;
protected $activity_repo; protected $activity_repo;
/** /**

View File

@ -22,6 +22,8 @@ use Illuminate\Contracts\Queue\ShouldQueue;
class QuoteCreatedNotification implements ShouldQueue class QuoteCreatedNotification implements ShouldQueue
{ {
public $delay = 5;
use UserNotifies; use UserNotifies;
public function __construct() public function __construct()

View File

@ -19,6 +19,8 @@ use stdClass;
class QuoteDeletedActivity implements ShouldQueue class QuoteDeletedActivity implements ShouldQueue
{ {
public $delay = 5;
protected $activity_repo; protected $activity_repo;
/** /**

View File

@ -19,6 +19,8 @@ use stdClass;
class QuoteEmailActivity implements ShouldQueue class QuoteEmailActivity implements ShouldQueue
{ {
public $delay = 5;
protected $activity_repo; protected $activity_repo;
/** /**

View File

@ -22,6 +22,9 @@ use Illuminate\Contracts\Queue\ShouldQueue;
class QuoteEmailedNotification implements ShouldQueue class QuoteEmailedNotification implements ShouldQueue
{ {
public $delay = 5;
use UserNotifies; use UserNotifies;
public function __construct() public function __construct()

View File

@ -19,6 +19,8 @@ use stdClass;
class QuoteRestoredActivity implements ShouldQueue class QuoteRestoredActivity implements ShouldQueue
{ {
public $delay = 5;
protected $activity_repo; protected $activity_repo;
/** /**

View File

@ -19,6 +19,8 @@ use stdClass;
class QuoteViewedActivity implements ShouldQueue class QuoteViewedActivity implements ShouldQueue
{ {
public $delay = 5;
protected $activity_repo; protected $activity_repo;
/** /**

View File

@ -91,9 +91,16 @@ class UpdateInvoicePayment
->workFlow() ->workFlow()
->save(); ->save();
event(new InvoiceWasUpdated($invoice, $invoice->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null)));
}); });
/* Remove the event updater from within the loop to prevent race conditions */
$invoices->each(function ($invoice) {
event(new InvoiceWasUpdated($invoice, $invoice->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null)));
});
$this->payment->saveQuietly(); $this->payment->saveQuietly();
return $this->payment; return $this->payment;

View File

@ -330,17 +330,17 @@ trait MakesInvoiceValues
// but that's no longer necessary. // but that's no longer necessary.
if (isset($item->tax_rate1)) { if (isset($item->tax_rate1)) {
$data[$key][$table_type.'.tax_rate1'] = round($item->tax_rate1, 2).'%'; $data[$key][$table_type.'.tax_rate1'] = floatval($item->tax_rate1).'%';
$data[$key][$table_type.'.tax1'] = &$data[$key][$table_type.'.tax_rate1']; $data[$key][$table_type.'.tax1'] = &$data[$key][$table_type.'.tax_rate1'];
} }
if (isset($item->tax_rate2)) { if (isset($item->tax_rate2)) {
$data[$key][$table_type.'.tax_rate2'] = round($item->tax_rate2, 2).'%'; $data[$key][$table_type.'.tax_rate2'] = floatval($item->tax_rate2).'%';
$data[$key][$table_type.'.tax2'] = &$data[$key][$table_type.'.tax_rate2']; $data[$key][$table_type.'.tax2'] = &$data[$key][$table_type.'.tax_rate2'];
} }
if (isset($item->tax_rate3)) { if (isset($item->tax_rate3)) {
$data[$key][$table_type.'.tax_rate3'] = round($item->tax_rate3, 2).'%'; $data[$key][$table_type.'.tax_rate3'] = floatval($item->tax_rate3).'%';
$data[$key][$table_type.'.tax3'] = &$data[$key][$table_type.'.tax_rate3']; $data[$key][$table_type.'.tax3'] = &$data[$key][$table_type.'.tax_rate3'];
} }

View File

@ -38,12 +38,11 @@ class RedisVsDatabaseTest extends TestCase
$currencies = Cache::get('currencies'); $currencies = Cache::get('currencies');
$currency = $currencies->filter(function ($item) { $currencies->filter(function ($item) {
return $item->id == 17; return $item->id == 17;
})->first(); })->first();
nlog(microtime(true) - $start);
$total_time = microtime(true) - $start;
$this->assertTrue(true); $this->assertTrue(true);
// nlog($total_time); // nlog($total_time);
@ -57,8 +56,7 @@ class RedisVsDatabaseTest extends TestCase
$currency = Currency::find(17); $currency = Currency::find(17);
$total_time = microtime(true) - $start; nlog(microtime(true) - $start);
$this->assertTrue(true); $this->assertTrue(true);
// nlog($total_time); // nlog($total_time);