modified jobs for sending mails

This commit is contained in:
2019-01-05 01:24:32 -06:00
parent 8db45f24d0
commit e022d2881a
5 changed files with 87 additions and 54 deletions
+20 -2
View File
@@ -6,6 +6,7 @@ use Illuminate\Console\Command;
use Carbon\Carbon; use Carbon\Carbon;
use DB; use DB;
use App\Jobs\SendEveMail;
use Commands\Library\CommandHelper; use Commands\Library\CommandHelper;
use App\Library\Finances\Helper\FinanceHelper; use App\Library\Finances\Helper\FinanceHelper;
use App\Library\Structures\StructureTaxHelper; use App\Library\Structures\StructureTaxHelper;
@@ -82,8 +83,6 @@ class CalculateMarketTax extends Command
$finalTaxes = 0.00; $finalTaxes = 0.00;
} }
//$finalTaxes = number_format($finalTaxes, 2, '.', ',');
//Get the info about the structures from the database //Get the info about the structures from the database
$info = CorpStructure::where(['corporation_id' => $corp->corporation_id])->first(); $info = CorpStructure::where(['corporation_id' => $corp->corporation_id])->first();
@@ -100,6 +99,22 @@ class CalculateMarketTax extends Command
$bill->year = $start->year; $bill->year = $start->year;
$bill->save(); $bill->save();
$mail = new EveMail;
$mail->sender = 93738489;
$mail->subject = 'Market Taxes Owed';
$mail->body = 'Year ' . $start->year . ' ' .
'Month: ' .
$start->month .
'<br>Market Taxes Owed: ' .
number_format($finalTaxes, 2, '.', ',') .
'<br>Please remit to Spatial Forces';
$mail->recipient = (int)$info->character_id;
$mail->recipient_type = 'character';
SendEveMail::dispatch($mail);
/*
//Retrieve the token for main character to send mails from //Retrieve the token for main character to send mails from
$token = EsiToken::where(['character_id' => 93738489])->first(); $token = EsiToken::where(['character_id' => 93738489])->first();
@@ -138,7 +153,10 @@ class CalculateMarketTax extends Command
} catch(RequestFailedException $e) { } catch(RequestFailedException $e) {
$this->line('Error is ' . $e); $this->line('Error is ' . $e);
} }
*/
} }
//Mark the job as finished //Mark the job as finished
$task->SetStopStatus(); $task->SetStopStatus();
+45 -13
View File
@@ -8,7 +8,10 @@ use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Foundation\Bus\Dispatchable;
use App\Library\Esi\Mail; use Seat\Eseye\Configuration;
use Seat\Eseye\Containers\EsiAuthentication;
use Seat\Eseye\Eseye;
use Seat\Eseye\Exceptions\RequestFailedException;
use App\Models\EveMail as EveMailModel; use App\Models\EveMail as EveMailModel;
@@ -21,6 +24,20 @@ class SendEveMail implements ShouldQueue
*/ */
protected $eveMail; protected $eveMail;
/**
* Timeout in seconds
*
* @var int
*/
public $timeout = 120;
/**
* Retries
*
* @var int
*/
public $retries = 3;
/** /**
* Create a new job instance. * Create a new job instance.
* *
@@ -43,21 +60,36 @@ class SendEveMail implements ShouldQueue
//Access the model in the queue for processing //Access the model in the queue for processing
$mail = $this->eveMail; $mail = $this->eveMail;
//Create a new Mail class variable //Retrieve the token for main character to send mails from
$esi = new Mail(); $token = EsiToken::where(['character_id'=> 93738489])->get();
//Process the mail from the model to send a new mail //Create the ESI authentication container
$esi->SendGeneralMail($mail->recepient, $mail->subject, $mail->body); $config = config('esi');
$authentication = new EsiAuthentication([
'client_id' => $config['client_id'],
'secret' => $config['secret'],
'refresh_token' => $token->refresh_token,
]);
} //Setup the Eseye class
$esi = new Eseye($authentication);
/** //Attemp to send the mail
* Determine the time the job should timeout try {
* $esi->setBody([
* @return \DateTime 'approved_cost' => 0,
*/ 'body' => $mail->body,
public function retryUntil() { 'recipients' => [[
return now()->addSeconds(5); 'recipient_id' => (int)$mail->recipient,
'recipient_type' => $mail->recipient_type,
]],
'subject' => $mail->subject,
])->invoke('post', '/characters/{character_id}/mail/', [
'character_id'=> 93738489,
]);
} catch(RequestFailedException $e) {
//
}
} }
/** /**
+9 -36
View File
@@ -15,7 +15,7 @@ use Seat\Eseye\Exceptions\RequestFailedException;
class Mail { class Mail {
public function SendGeneralMail($recipient, $subject, $body) { public function SendMail($recipient, $rType, $subject, $body) {
//Retrieve the token for main character to send mails from //Retrieve the token for main character to send mails from
$token = EsiToken::where(['character_id' => 93738489])->get(); $token = EsiToken::where(['character_id' => 93738489])->get();
//Create the ESI authentication container //Create the ESI authentication container
@@ -28,48 +28,21 @@ class Mail {
$esi = new Eseye($authentication); $esi = new Eseye($authentication);
try { try {
$esi->setBody([ $esi->setBody([
'approved_cost' => 0,
'body' => $body, 'body' => $body,
'receipients' => [ 'recipients' => [[
'recipient_id'=> $recipient, 'recipient_id' => (int)$recipient,
'recipient_type' => 'character', 'recipient_type' => $rType,
], ]],
'subject' => $subject, 'subject' => $subject,
])->invoke('post', '/characters/{character_id}/mail/', [ ])->invoke('post', '/characters/{character_id}/mail/', [
'character_id' => 93738489, 'character_id'=> 93738489,
]); ]);
} catch(RequestFailedException $e) { } catch(RequestFailedException $e) {
return null; return 1;
} }
}
public function SendMail($charId, $taxAmount, $subject, $body) { return 0;
//Retrieve the token for Amund Risalo
$token = DB::table('EsiTokens')->where('character_id', 93738489)->get();
$configuration = Configuration::getInstance();
$configuration->cache = NullCache::class;
//Create the ESI authentication container
$config = config('esi');
$authentication = new EsiAuthentication([
'client_id' => $config['client_id'],
'secret' => $config['secret'],
'refresh_token' => $token[0]->refresh_token,
]);
//Create the esi class variable
$esi = new Eseye($authentication);
try {
$esi->setBody([
'body' => $body,
'receipients' => [
'recipient_id'=> $charId,
'recipient_type' => 'character',
],
'subject' => $subject,
])->invoke('post', '/characters/{character_id}/mail/', [
'character_id' => 93738489,
]);
} catch(RequestFailedException $e) {
return $e->getEsiResponse();
}
} }
} }
+10
View File
@@ -11,4 +11,14 @@ class EveMail extends Model
//Timestamps //Timestamps
public $timestamps = 'true'; public $timestamps = 'true';
protected $fillable = [
'sender',
'recipient',
'recipient_type',
'subject',
'body',
'created_at',
'updated_at',
];
} }
@@ -18,12 +18,12 @@ class CreateEveMailsTable extends Migration
$table->increments('id'); $table->increments('id');
$table->string('sender'); $table->string('sender');
$table->string('recipient'); $table->string('recipient');
$table->string('subject'); $table->string('recipient_type');
$table->string('body'); $table->text('subject');
$table->text('body');
$table->timestamps(); $table->timestamps();
}); });
} }
} }
/** /**