moon mailer stuff
This commit is contained in:
120
app/Jobs/ProcessSendEveMailJob.php
Normal file
120
app/Jobs/ProcessSendEveMailJob.php
Normal file
@@ -0,0 +1,120 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Jobs;
|
||||||
|
|
||||||
|
//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;
|
||||||
|
|
||||||
|
//Seat stuff
|
||||||
|
use Seat\Eseye\Configuration;
|
||||||
|
use Seat\Eseye\Containers\EsiAuthentication;
|
||||||
|
use Seat\Eseye\Eseye;
|
||||||
|
use Seat\Eseye\Exceptions\RequestFailedException;
|
||||||
|
|
||||||
|
//Models
|
||||||
|
use App\Models\Esi\EsiScope;
|
||||||
|
use App\Models\Esi\EsiToken;
|
||||||
|
use App\Models\Mail\EveMail;
|
||||||
|
use App\Models\Jobs\JobStatus;
|
||||||
|
|
||||||
|
class ProcessSendEveMailJob implements ShouldQueue
|
||||||
|
{
|
||||||
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Timeout in seconds
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
public $timeout = 120;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retries
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
public $retries = 3;
|
||||||
|
|
||||||
|
private $body;
|
||||||
|
private $recipient;
|
||||||
|
private $recipient_type;
|
||||||
|
private $subject;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new job instance.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct(EveMail $mail) {
|
||||||
|
$this->body = $mail->body;
|
||||||
|
$this->recipient = $mail->recipient;
|
||||||
|
$this->recipient_type = $mail->recipient_type;
|
||||||
|
$this->subject = $mail->subject;
|
||||||
|
|
||||||
|
$this->connection = 'redis';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute the job.
|
||||||
|
* Utilized by using SendEveMailJob::dispatch($mail);
|
||||||
|
* The model is passed into the dispatch function, then added to the queue
|
||||||
|
* for processing.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function handle()
|
||||||
|
{
|
||||||
|
//Get the esi configuration
|
||||||
|
$config = config('esi');
|
||||||
|
|
||||||
|
//Retrieve the token for main character to send mails from
|
||||||
|
$token = EsiToken::where(['character_id'=> 92626011])->first();
|
||||||
|
|
||||||
|
//Create the ESI authentication container
|
||||||
|
$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
|
||||||
|
try {
|
||||||
|
$esi->setBody([
|
||||||
|
'approved_cost' => 100,
|
||||||
|
'body' => $this->body,
|
||||||
|
'recipients' => [[
|
||||||
|
'recipient_id' => (int)92626011,
|
||||||
|
'recipient_type' => $this->recipient_type,
|
||||||
|
]],
|
||||||
|
'subject' => $this->subject,
|
||||||
|
])->invoke('post', '/characters/{character_id}/mail/', [
|
||||||
|
'character_id'=> 92626011,
|
||||||
|
]);
|
||||||
|
} catch(RequestFailedException $e) {
|
||||||
|
Log::warning($e);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The job failed to process.
|
||||||
|
*
|
||||||
|
* @param Exception $exception
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function failed($exception)
|
||||||
|
{
|
||||||
|
Log::critical($exception);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -73,14 +73,14 @@ class SendEveMailJob implements ShouldQueue
|
|||||||
$config = config('esi');
|
$config = config('esi');
|
||||||
|
|
||||||
//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'=> $config['primary']])->get();
|
$token = EsiToken::where(['character_id'=> 92626011])->first();
|
||||||
|
|
||||||
//Create the ESI authentication container
|
//Create the ESI authentication container
|
||||||
$config = config('esi');
|
$config = config('esi');
|
||||||
$authentication = new EsiAuthentication([
|
$authentication = new EsiAuthentication([
|
||||||
'client_id' => $config['client_id'],
|
'client_id' => $config['client_id'],
|
||||||
'secret' => $config['secret'],
|
'secret' => $config['secret'],
|
||||||
'refresh_token' => $token[0]->refresh_token,
|
'refresh_token' => $token->refresh_token,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
//Setup the Eseye class
|
//Setup the Eseye class
|
||||||
@@ -89,15 +89,15 @@ class SendEveMailJob implements ShouldQueue
|
|||||||
//Attemp to send the mail
|
//Attemp to send the mail
|
||||||
try {
|
try {
|
||||||
$esi->setBody([
|
$esi->setBody([
|
||||||
'approved_cost' => 0,
|
'approved_cost' => 100,
|
||||||
'body' => $this->body,
|
'body' => $this->body,
|
||||||
'recipients' => [[
|
'recipients' => [[
|
||||||
'recipient_id' => (int)$this->recipient,
|
'recipient_id' => 92626011,
|
||||||
'recipient_type' => $this->recipient_type,
|
'recipient_type' => $this->recipient_type,
|
||||||
]],
|
]],
|
||||||
'subject' => $this->subject,
|
'subject' => $this->subject,
|
||||||
])->invoke('post', '/characters/{character_id}/mail/', [
|
])->invoke('post', '/characters/{character_id}/mail/', [
|
||||||
'character_id'=> $config['primary'],
|
'character_id'=> 92626011,
|
||||||
]);
|
]);
|
||||||
} catch(RequestFailedException $e) {
|
} catch(RequestFailedException $e) {
|
||||||
Log::warning($e);
|
Log::warning($e);
|
||||||
|
|||||||
Reference in New Issue
Block a user