Xboard/app/Jobs/SendEmailJob.php

43 lines
933 B
PHP

<?php
namespace App\Jobs;
use App\Services\MailService;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
class SendEmailJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
protected $params;
public $tries = 3;
public $timeout = 10;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct($params, $queue = 'send_email')
{
$this->onQueue($queue);
$this->params = $params;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
$mailLog = MailService::sendEmail($this->params);
if($mailLog['error']){
$this->release(); //发送失败将触发重试
}
}
}