updated delays for jobs

This commit is contained in:
2020-05-10 21:52:04 -05:00
parent 524f2051ea
commit 08844a50f7
15 changed files with 272 additions and 31 deletions

View File

@@ -99,7 +99,7 @@ class FlexStructureCommand extends Command
$mail->body = $body;
$mail->recipient = (int)$structure->requestor_id;
$mail->recipient_type = 'character';
ProcessSendEveMailJob::dispatch($mail)->onQueue('mail')->delay($delay);
ProcessSendEveMailJob::dispatch($mail)->onQueue('mail')->delay(Carbon::now()->addSeconds($delay));
//Increment the delay for the mail to not hit the rate limits
$delay += 60;

View File

@@ -107,7 +107,7 @@ class MoonMailerCommand extends Command
$mail->body = $body;
$mail->recipient = (int)$contact->Contact;
$mail->recipient_type = 'character';
ProcessSendEveMailJob::dispatch($mail)->onQueue('mail')->delay($delay);
ProcessSendEveMailJob::dispatch($mail)->onQueue('mail')->delay(Carbon::now()->addSeconds($delay));
//Increment the delay for the mail to not hit rate limits
$delay += 30;

View File

@@ -160,7 +160,7 @@ class ContractAdminController extends Controller
$mail->body = $body;
$mail->sender = $config['primary'];
//Dispatch the mail job
ProcessSendEveMailJob::dispatch($mail)->onQueue('mail');
ProcessSendEveMailJob::dispatch($mail)->onQueue('mail')->delay(Carbon::now()->addSeconds(5));
//Tidy up the contract by doing a few things.
$this->TidyContract($contract, $bid);
@@ -193,6 +193,6 @@ class ContractAdminController extends Controller
$mail->recipient = $config['alliance'];
$mail->recipient_type = 'alliance';
$mail->body = "A new contract is available for the alliance contracting system. Please check out <a href='https://services.w4rp.space'>Services Site</a> if you want to bid on the production contract.<br><br>Sincerely,<br>Warped Intentions Leadership";
ProcessSendEveMailJob::dispatch($mail)->onQueue('mail');
ProcessSendEveMailJob::dispatch($mail)->onQueue('mail')->delay(Carbon::now()->addSeconds(5));
}
}

View File

@@ -7,9 +7,6 @@ use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Log;
//Jobs
use App\Jobs\ProcessSendEveMailJob;
//Models
use App\Models\Logistics\AnchorStructure;
use App\Models\Jobs\JobSendEveMail;

View File

@@ -78,7 +78,7 @@ class StructureRequestController extends Controller
$mail->body = $body;
$mail->recipient = (int)$fc->character_id;
$mail->recipient_type = 'character';
ProcessSendEveMailJob::dispatch($mail)->onQueue('mail')->delay($delay);
ProcessSendEveMailJob::dispatch($mail)->onQueue('mail')->delay(Carbon::now()->addSeconds($delay));
$delay += 15;
}

View File

@@ -136,7 +136,7 @@ class MoonsAdminController extends Controller
$mail->body = $body;
$mail->recipient = (int)$moon->requestor_id;
$mail->recipient_type = 'character';
ProcessSendEveMailJob::dispatch($mail)->onQueue('mail');
ProcessSendEveMailJob::dispatch($mail)->onQueue('mail')->delay(Carbon::now()->addSeconds(5));
return redirect('/moons/admin/display/request')->with('success', 'Moon has been processed, and mail has been sent out.');
}

View File

@@ -0,0 +1,173 @@
<?php
namespace App\Jobs\Commands\Moons;
//Internal Libraries
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Carbon\Carbon;
//Jobs
use App\Jobs\ProcessSendEveMailJob;
//Library
use App\Library\Moons\MoonCalc;
use App\Library\Esi\Esi;
use Seat\Eseye\Exceptions\RequestFailedException;
//Models
use App\Models\Moon\RentalMoon;
use App\Models\MoonRent\MoonRental;
use App\Models\Jobs\JobSendEveMail;
use App\Models\Mail\SentMail;
class MoonRentalInvoiceCreate implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
/**
* Today's date
*
* @var Carbon
*/
private $today;
/**
* Rental Contact
*
* @var int
*/
private $contact;
/**
* Moon Rentals
*
* @var MoonRental
*/
private $rentals;
/**
* ESI mail delay to not hit limit of 4 / min
*
* @var int
*/
private $delay;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct($contact, $mailDelay)
{
//Renter contact
$this->contact = $contact;
//Setup today's date
$this->today = Carbon::now();
$this->today->second = 1;
$this->today->minute = 0;
$this->today->hour = 0;
//Setup the delay
$this->delay = $mailDelay;
//Null out unused variables when calling the construct
$this->rentals = null;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
//Create needed variables
$moonCalc = new MoonCalc;
$body = null;
$delay = 60;
$config = config('esi');
//Get the rentals the contact is renting
$this->rentals = MoonRental::where([
'Contact' => $this->contact,
])->get();
//Totalize the cost of the moons
$cost = $this->TotalizeMoonCost();
//Get the list of the moons in a list format
$listItems = $this->GetMoonList();
//Build a mail body to be sent to the renter
$body = "Moon Rent is due for the following moons:<br>";
foreach($listItems as $item) {
$body .= $item . "<br>";
}
$body .= "The price for the next's month rent is " . number_format($cost, 2, ".", ",") . " ISK<br>";
$body .= "Please remit payment to Spatial Forces on the 1st should you continue to wish to rent the moon.<br>";
$body .= "Sincerely,<br>";
$body .= "Warped Intentions Leadership<br>";
//Dispatch a new mail job
$mail = new JobSendEveMail;
$mail->sender = $config['primary'];
$mail->subject = "Warped Intentions Moon Rental Payment Due for " . $today->englishMonth;
$mail->body = $body;
$mail->recipient = (int)$contact->Contact;
$mail->recipient_type = 'character';
ProcessSendEveMailJob::dispatch($mail)->onQueue('mail')->delay(Carbon::now()->addSeconds($this->delay));
MoonRentalUpdate::dispatch($this->rentals);
}
private function TotalizeMoonCost() {
$totalCost = 0.00;
$price = null;
foreach($this->rentals as $rental) {
$moon = RentalMoon::where([
'System' => $rental->System,
'Planet' => $rental->Planet,
'Moon' => $rental->Moon,
])->first();
$end = new Carbon($rental->Paid_Until);
//If today is greater than the rental end, then calculate the moon cost
if($today->greaterThanOrEqualTo($end)) {
//Get the updated price for the moon
$price = $moonCalc->SpatialMoons($moon->FirstOre, $moon->FirstQuantity, $moon->SecondOre, $moon->SecondQuantity,
$moon->ThirdOre, $moon->ThirdQuantity, $moon->FourthOre, $moon->FourthQuantity);
//Check the type and figure out which price to add in
if($rental->Type == 'alliance') {
$totalCost += $price['alliance'];
} else {
$totalCost += $price['outofalliance'];
}
}
}
//Return the total cost to the calling function
return $totalCost;
}
private function GetMoonList() {
//Declare the list variable as an array
$list = array();
//Foreach of the moons, build the system, planet, and moon
foreach($this->rentals as $moon) {
$temp = 'Moon: ' . $moon->System . ' - ' . $moon->Planet . ' - ' . $moon->Moon;
array_push($list, $temp);
}
//Return the list
return $list;
}
}

View File

@@ -2,11 +2,18 @@
namespace App\Jobs\Commands\Moons;
//Internal Library
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Log;
//App Library
//App Models
class MoonRentalInvoiceVerify implements ShouldQueue
{

View File

@@ -0,0 +1,34 @@
<?php
namespace App\Jobs;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
class MoonRentalUpdate implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
//
}
}

View File

@@ -9,6 +9,7 @@ use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Log;
use Carbon\Carbon;
//Library
use App\Library\Esi\Esi;
@@ -84,10 +85,6 @@ class ProcessSendEveMailJob implements ShouldQueue
//Create the ESI authentication container
$esi = $esiHelper->SetupEsiAuthentication($token);
//Set caching to null
$configuration = Configuration::getInstance();
$configuration->cache = NullCache::class;
//Attemp to send the mail
try {
$esi->setBody([

View File

@@ -48,7 +48,7 @@ class Esi {
$mail->recipient = (int)$charId;
$mail->recipient_type = 'character';
ProcessSendEveMailJob::dispatch($mail)->onQueue('mail')->delay(5);
ProcessSendEveMailJob::dispatch($mail)->onQueue('mail')->delay(Carbon::now()->addSeconds(5));
return false;
}

View File

@@ -9,9 +9,7 @@ namespace App\Library\Finances\Helper;
//Internal Library
use Log;
//Job
use App\Jobs\ProcessSendEveMailJob;
use Carbon\Carbon;
//Models
use App\Models\Esi\EsiToken;

View File

@@ -0,0 +1,31 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateMailWaitingQueueTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('mail_waiting_queue', function (Blueprint $table) {
$table->bigIncrements('id');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('mail_waiting_queue');
}
}

View File

@@ -59,12 +59,15 @@ return array(
'App\\Http\\Middleware\\TrustProxies' => $baseDir . '/app/Http/Middleware/TrustProxies.php',
'App\\Http\\Middleware\\VerifyCsrfToken' => $baseDir . '/app/Http/Middleware/VerifyCsrfToken.php',
'App\\JobProcessCorpJournal' => $baseDir . '/app/Models/Jobs/JobProcessCorpJournal.php',
'App\\Jobs\\Commands\\FetchMoonObserversJob' => $baseDir . '/app/Jobs/Commands/FetchMoonObserversJob.php',
'App\\Jobs\\Commands\\FetchRentalMoonLedgerJob' => $baseDir . '/app/Jobs/Commands/FetchRentalMoonLedgerJob.php',
'App\\Jobs\\Commands\\FetchRentalMoonObserversJob' => $baseDir . '/app/Jobs/Commands/FetchRentalMoonObserversJob.php',
'App\\Jobs\\FetchMoonLedgerJob' => $baseDir . '/app/Jobs/Commands/FetchMoonLedgerJob.php',
'App\\Jobs\\MoonRentalInvoiceJob' => $baseDir . '/app/Jobs/Commands/MoonRentalInvoiceJob.php',
'App\\Jobs\\MoonRentalPaymentJob' => $baseDir . '/app/Jobs/Commands/MoonRentalPaymentJob.php',
'App\\Jobs\\Commands\\FetchRentalMoonLedgerJob' => $baseDir . '/app/Jobs/Commands/Not Used/FetchRentalMoonLedgerJob.php',
'App\\Jobs\\Commands\\FetchRentalMoonObserversJob' => $baseDir . '/app/Jobs/Commands/Not Used/FetchRentalMoonObserversJob.php',
'App\\Jobs\\Commands\\Moons\\FetchMoonLedgerJob' => $baseDir . '/app/Jobs/Commands/Moons/FetchMoonLedgerJob.php',
'App\\Jobs\\Commands\\Moons\\FetchMoonObserversJob' => $baseDir . '/app/Jobs/Commands/Moons/FetchMoonObserversJob.php',
'App\\Jobs\\Commands\\Moons\\MoonRentalInvoiceCreate' => $baseDir . '/app/Jobs/Commands/Moons/MoonRentalInvoiceCreate.php',
'App\\Jobs\\Commands\\Moons\\MoonRentalInvoiceVerify' => $baseDir . '/app/Jobs/Commands/Moons/MoonRentalInvoiceVerify.php',
'App\\Jobs\\Commands\\Moons\\MoonRentalPaymentJob' => $baseDir . '/app/Jobs/Commands/Moons/MoonRentalPaymentJob.php',
'App\\Jobs\\Commands\\Moons\\PurgeMoonLedgerJob' => $baseDir . '/app/Jobs/Commands/Moons/PurgeMoonLedgerJob.php',
'App\\Jobs\\MoonRentalUpdate' => $baseDir . '/app/Jobs/Commands/Moons/MoonRentalUpdate.php',
'App\\Jobs\\ProcessAssetsJob' => $baseDir . '/app/Jobs/ProcessAssetsJob.php',
'App\\Jobs\\ProcessSendEveMailJob' => $baseDir . '/app/Jobs/ProcessSendEveMailJob.php',
'App\\Jobs\\ProcessStructureJob' => $baseDir . '/app/Jobs/ProcessStructureJob.php',
@@ -88,7 +91,6 @@ return array(
'App\\Library\\Moons\\MiningLedgerHelper' => $baseDir . '/app/Library/Moons/MiningLedgerHelper.php',
'App\\Library\\Moons\\MoonCalc' => $baseDir . '/app/Library/Moons/MoonCalc.php',
'App\\Library\\SRP\\SRPHelper' => $baseDir . '/app/Library/SRP/SRPHelper.php',
'App\\Library\\Structures\\MarketHelper' => $baseDir . '/app/Library/Structures/MarketHelper.php',
'App\\Library\\Structures\\StructureHelper' => $baseDir . '/app/Library/Structures/StructureHelper.php',
'App\\Library\\Taxes\\TaxesHelper' => $baseDir . '/app/Library/Taxes/TaxesHelper.php',
'App\\Library\\Wiki\\WikiHelper' => $baseDir . '/app/Library/Wiki/WikiHelper.php',

View File

@@ -528,12 +528,15 @@ class ComposerStaticInitc3f953f8a7291d41a76e1664339777c9
'App\\Http\\Middleware\\TrustProxies' => __DIR__ . '/../..' . '/app/Http/Middleware/TrustProxies.php',
'App\\Http\\Middleware\\VerifyCsrfToken' => __DIR__ . '/../..' . '/app/Http/Middleware/VerifyCsrfToken.php',
'App\\JobProcessCorpJournal' => __DIR__ . '/../..' . '/app/Models/Jobs/JobProcessCorpJournal.php',
'App\\Jobs\\Commands\\FetchMoonObserversJob' => __DIR__ . '/../..' . '/app/Jobs/Commands/FetchMoonObserversJob.php',
'App\\Jobs\\Commands\\FetchRentalMoonLedgerJob' => __DIR__ . '/../..' . '/app/Jobs/Commands/FetchRentalMoonLedgerJob.php',
'App\\Jobs\\Commands\\FetchRentalMoonObserversJob' => __DIR__ . '/../..' . '/app/Jobs/Commands/FetchRentalMoonObserversJob.php',
'App\\Jobs\\FetchMoonLedgerJob' => __DIR__ . '/../..' . '/app/Jobs/Commands/FetchMoonLedgerJob.php',
'App\\Jobs\\MoonRentalInvoiceJob' => __DIR__ . '/../..' . '/app/Jobs/Commands/MoonRentalInvoiceJob.php',
'App\\Jobs\\MoonRentalPaymentJob' => __DIR__ . '/../..' . '/app/Jobs/Commands/MoonRentalPaymentJob.php',
'App\\Jobs\\Commands\\FetchRentalMoonLedgerJob' => __DIR__ . '/../..' . '/app/Jobs/Commands/Not Used/FetchRentalMoonLedgerJob.php',
'App\\Jobs\\Commands\\FetchRentalMoonObserversJob' => __DIR__ . '/../..' . '/app/Jobs/Commands/Not Used/FetchRentalMoonObserversJob.php',
'App\\Jobs\\Commands\\Moons\\FetchMoonLedgerJob' => __DIR__ . '/../..' . '/app/Jobs/Commands/Moons/FetchMoonLedgerJob.php',
'App\\Jobs\\Commands\\Moons\\FetchMoonObserversJob' => __DIR__ . '/../..' . '/app/Jobs/Commands/Moons/FetchMoonObserversJob.php',
'App\\Jobs\\Commands\\Moons\\MoonRentalInvoiceCreate' => __DIR__ . '/../..' . '/app/Jobs/Commands/Moons/MoonRentalInvoiceCreate.php',
'App\\Jobs\\Commands\\Moons\\MoonRentalInvoiceVerify' => __DIR__ . '/../..' . '/app/Jobs/Commands/Moons/MoonRentalInvoiceVerify.php',
'App\\Jobs\\Commands\\Moons\\MoonRentalPaymentJob' => __DIR__ . '/../..' . '/app/Jobs/Commands/Moons/MoonRentalPaymentJob.php',
'App\\Jobs\\Commands\\Moons\\PurgeMoonLedgerJob' => __DIR__ . '/../..' . '/app/Jobs/Commands/Moons/PurgeMoonLedgerJob.php',
'App\\Jobs\\MoonRentalUpdate' => __DIR__ . '/../..' . '/app/Jobs/Commands/Moons/MoonRentalUpdate.php',
'App\\Jobs\\ProcessAssetsJob' => __DIR__ . '/../..' . '/app/Jobs/ProcessAssetsJob.php',
'App\\Jobs\\ProcessSendEveMailJob' => __DIR__ . '/../..' . '/app/Jobs/ProcessSendEveMailJob.php',
'App\\Jobs\\ProcessStructureJob' => __DIR__ . '/../..' . '/app/Jobs/ProcessStructureJob.php',
@@ -557,7 +560,6 @@ class ComposerStaticInitc3f953f8a7291d41a76e1664339777c9
'App\\Library\\Moons\\MiningLedgerHelper' => __DIR__ . '/../..' . '/app/Library/Moons/MiningLedgerHelper.php',
'App\\Library\\Moons\\MoonCalc' => __DIR__ . '/../..' . '/app/Library/Moons/MoonCalc.php',
'App\\Library\\SRP\\SRPHelper' => __DIR__ . '/../..' . '/app/Library/SRP/SRPHelper.php',
'App\\Library\\Structures\\MarketHelper' => __DIR__ . '/../..' . '/app/Library/Structures/MarketHelper.php',
'App\\Library\\Structures\\StructureHelper' => __DIR__ . '/../..' . '/app/Library/Structures/StructureHelper.php',
'App\\Library\\Taxes\\TaxesHelper' => __DIR__ . '/../..' . '/app/Library/Taxes/TaxesHelper.php',
'App\\Library\\Wiki\\WikiHelper' => __DIR__ . '/../..' . '/app/Library/Wiki/WikiHelper.php',