You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
1.0 KiB
47 lines
1.0 KiB
<?php
|
|
|
|
namespace app\home\job;
|
|
|
|
use think\facade\Log;
|
|
use think\queue\Job;
|
|
|
|
class SendEmail
|
|
{
|
|
|
|
/**
|
|
* @desc 发送邮件
|
|
* @param Job $job
|
|
* @param $data
|
|
* @return void
|
|
*/
|
|
public function fire(Job $job, $data)
|
|
{
|
|
trace('新任务', 'info');
|
|
$phpEmail = new \app\utility\SendEmail();
|
|
$success = false;
|
|
for($times = 1; $times <= 3; $times++) {
|
|
$bool = $phpEmail->sendEmail($data['email'], $data['title'], $data['subject']);
|
|
if ($bool) {
|
|
$success = true;
|
|
break;
|
|
}
|
|
|
|
trace($job->getJobId().'---重试-----'.$times, 'info');
|
|
}
|
|
|
|
// 任务失败
|
|
if (!$success) {
|
|
trace($job->getJobId().'---失败-------'.json_encode($data), 'info');
|
|
}
|
|
|
|
// 删除任务
|
|
$job->delete();
|
|
}
|
|
|
|
public function failed($data)
|
|
{
|
|
// 失败任务
|
|
$dataStr = json_encode($data);
|
|
trace('queue job 任务失败---'.$dataStr, 'error');
|
|
}
|
|
}
|