Files
portal-api/app/Jobs/Mail/SendInformationVirtualMachine.php
T
2025-07-24 16:18:27 +07:00

73 lines
2.0 KiB
PHP

<?php
namespace App\Jobs\Mail;
use App\Http\Services\Telegram;
use App\Mail\CreateVirtualMachine;
use Carbon\Carbon;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Mail;
class SendInformationVirtualMachine implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public $data = [];
public $customer;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct($data = [],$customer = [])
{
$this->data = $data;
$this->customer = $customer;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
try {
$email = new CreateVirtualMachine(2,$this->data);
Mail::to($this->customer->email)->send($email);
\App\Models\Mail::create([
'template_id' => 2,
'subject' => $email->envelope()->subject,
'to' => $this->customer->email,
'customer_id' => $this->customer->id,
'message' => $email->render()
]);
} catch (\Exception $exception)
{
throw new \Exception( $exception->getMessage());
}
}
public function failed(\Throwable $exception, Telegram $telegram)
{
Log::channel('Custom')->info("=================================");
Log::channel('Custom')->info("Thông báo lỗi lúc: " .Carbon::now());
Log::channel('Custom')->info("Notification Send Information VirtualMachine: ");
Log::channel('Custom')->info("========");
Log::channel('Custom')->info($exception->getMessage());
Log::channel('Custom')->info("=================================");
$telegram->SendErrorMessage(json_decode($exception->getMessage()));
}
}