tweaked some jobs

This commit is contained in:
2021-03-18 19:31:26 +09:00
parent 7aee591a2c
commit 466a1750bd
4 changed files with 76 additions and 54 deletions

View File

@@ -51,7 +51,7 @@ class MiningTaxesDataCleanup extends Command
$task->SetStartStatus(); $task->SetStartStatus();
//Clean up old data //Clean up old data
Ledger::where(['updated_at', '<', Carbon::now()->subDays(120)])->delete(); Ledger::where(['updated_at', '<', Carbon::now()->subDays(90)])->delete();
//Set the task as finished //Set the task as finished
$task->SetStopStatus(); $task->SetStopStatus();

View File

@@ -134,6 +134,18 @@ class MiningTaxesInvoices extends Command
$body .= "<br>"; $body .= "<br>";
$body .= "<br>Sincerely,<br>Warped Intentions Leadership<br>"; $body .= "<br>Sincerely,<br>Warped Intentions Leadership<br>";
//Check if the mail body is greater than 2000 characters. If greater than 2,000 characters, then
if(sizeof($body) > 2000) {
$body = "Dear Miner,<br><br>";
$body .= "Total Value of Ore Mined: " . number_format($totalPrice, 2, ".", ",") . " ISK.";
$body .= "<br><br>";
$body .= "Please remit " . number_format($invoiceAmount, 2, ".", ",") . " ISK to Spatial Forces by " . $dateDue . "<br>";
$body .= "Set the reason for transfer as MMT: " . $invoiceId . "<br>";
$body .= "The mining taxes are currently set to " . $numberMiningTax . "%.<br>";
$body .= "<br>";
$body .= "<br>Sincerely,<br>Warped Intentions Leadership<br>";
}
//Mail the invoice to the character if the character is in //Mail the invoice to the character if the character is in
//Warped Intentions or Legacy //Warped Intentions or Legacy
$subject = 'Warped Intentions Mining Taxes'; $subject = 'Warped Intentions Mining Taxes';

View File

@@ -125,40 +125,46 @@ class ProcessSendEveMailJob implements ShouldQueue
switch($errorCode) { switch($errorCode) {
case 400: //Bad Request case 400: //Bad Request
$this->release(15); Log::critical("Bad request has occurred in ProcessSendEveMailJob. Job has been discarded");
return 0;
break; break;
case 401: //Unauthorized Request case 401: //Unauthorized Request
$this->release(15); Log::critical("Unauthorized request has occurred in ProcessSendEveMailJob at " . Carbon::now()->toDateTimeString() . ".\r\nCancelling the job.");
return 0;
break; break;
case 403: //Forbidden case 403: //Forbidden
$this->release(15); Log::critical("ProcessSendEveMailJob has incurred a forbidden error. Cancelling the job.");
return 0;
break; break;
case 420: //Error Limited case 420: //Error Limited
Log::warning("Error rate limit occurred in ProcessSendEveMailJob. Restarting job in 120 seconds."); Log::warning("Error rate limit occurred in ProcessSendEveMailJob. Restarting job in 120 seconds.");
$this->release(120); $this->release(120);
break; break;
case 500: //Internal Server Error case 500: //Internal Server Error
Log::critical("Internal Server Error for ESI in ProcessSendEveMailJob"); Log::critical("Internal Server Error for ESI in ProcessSendEveMailJob. Attempting a restart in 120 seconds.");
return 0; $this->release(120);
break; break;
case 503: //Service Unavailable case 503: //Service Unavailable
Log::critical("Service Unavailabe for ESI in ProcessSendEveMailJob"); Log::critical("Service Unavailabe for ESI in ProcessSendEveMailJob. Releasing the job back to the queue in 30 seconds.");
$this->release(15); $this->release(30);
break; break;
case 504: //Gateway Timeout case 504: //Gateway Timeout
Log::critical("Gateway timeout in ProcessSendEveMailJob"); Log::critical("Gateway timeout in ProcessSendEveMailJob. Releasing the job back to the queue in 30 seconds.");
$this->release(15); $this->release(30);
break; break;
case 520: //Internal Error -- Mostly comes when rate limited hit case 520: //Internal Error -- Mostly comes when rate limited hit
$this->release(15); Log::warning("Rate limit hit for ProcessSendEveMailJob. Releasing the job back to the queue in 30 seconds.");
$this->release(30);
break;
case 201:
$this->SaveSentRecord($this->sender, $this->subject, $this->body, $this->recipient, $this->recipient_type);
$this->delete();
break; break;
default: //If not an error, then just break out of the switch statement default: //If not an error, then just break out of the switch statement
break; break;
} }
$this->SaveSentRecord($this->sender, $this->subject, $this->body, $this->recipient, $this->recipient_type);
$this->delete(); return 0;
} }
/** /**

View File

@@ -68,51 +68,55 @@ class ProcessMiningTaxesLedgersJob implements ShouldQueue
$mHelper = new MoonCalc; $mHelper = new MoonCalc;
$config = config('esi'); $config = config('esi');
//Get some of the basic information we need to work with //Create a starting date for the ledger
$charName = $lookup->CharacterIdToName($this->ledger->character_id); $ledgerDate = Carbon::createFromFormat('Y-m-d', $this->ledger->last_updated);
//Get the type name from the ledger ore
$typeName = $lookup->ItemIdToName($this->ledger->type_id); //If the ledger is more than one day old, then process it, otherwise, we don't process it
//Get the price from the helper function //or add it to the database as it may still be updating.
$price = $mHelper->CalculateOrePrice($this->ledger->type_id); if($ledgerDate->lessThan(Carbon::now()->subDay())) {
//Calculate the total price based on the amount //Get some of the basic information we need to work with
$amount = (($price * $this->ledger->quantity) * $config['refine_rate']); $charName = $lookup->CharacterIdToName($this->ledger->character_id);
//Get the type name from the ledger ore
$typeName = $lookup->ItemIdToName($this->ledger->type_id);
//Get the price from the helper function
$price = $mHelper->CalculateOrePrice($this->ledger->type_id);
//Calculate the total price based on the amount
$amount = (($price * $this->ledger->quantity) * $config['refine_rate']);
$found = Ledger::where([ $found = Ledger::where([
'character_id' => $this->ledger->character_id,
'observer_id' => $this->observerId,
'type_id' => $this->ledger->type_id,
'last_updated' => $this->ledger->last_updated,
])->count();
if($found > 0) {
Ledger::where([
'character_id' => $this->ledger->character_id, 'character_id' => $this->ledger->character_id,
'character_name' => $charName,
'observer_id' => $this->observerId, 'observer_id' => $this->observerId,
'type_id' => $this->ledger->type_id, 'type_id' => $this->ledger->type_id,
'quantity' => $this->ledger->quantity,
'last_updated' => $this->ledger->last_updated, 'last_updated' => $this->ledger->last_updated,
])->update([ ])->count();
'character_id' => $this->ledger->character_id,
'character_name' => $charName, if($found > 0) {
'observer_id' => $this->observerId, Ledger::where([
'last_updated' => $this->ledger->last_updated, 'character_id' => $this->ledger->character_id,
'type_id' => $this->ledger->type_id, 'character_name' => $charName,
'ore_name' => $typeName, 'observer_id' => $this->observerId,
'quantity' => $this->ledger->quantity, 'type_id' => $this->ledger->type_id,
'amount' => $amount, 'quantity' => $this->ledger->quantity,
]); 'last_updated' => $this->ledger->last_updated,
} else { ])->update([
$ledg = new Ledger; 'last_updated' => $this->ledger->last_updated,
$ledg->character_id = $this->ledger->character_id; 'quantity' => $this->ledger->quantity,
$ledg->character_name = $charName; 'amount' => $amount,
$ledg->observer_id = $this->observerId; ]);
$ledg->last_updated = $this->ledger->last_updated; } else {
$ledg->type_id = $this->ledger->type_id; $ledg = new Ledger;
$ledg->ore_name = $typeName; $ledg->character_id = $this->ledger->character_id;
$ledg->quantity = $this->ledger->quantity; $ledg->character_name = $charName;
$ledg->amount = $amount; $ledg->observer_id = $this->observerId;
$ledg->save(); $ledg->last_updated = $this->ledger->last_updated;
$ledg->type_id = $this->ledger->type_id;
$ledg->ore_name = $typeName;
$ledg->quantity = $this->ledger->quantity;
$ledg->amount = $amount;
$ledg->save();
}
} }
return 0;
} }
} }