luck-draw/app/job/NotifySms.php

37 lines
994 B
PHP
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<?php
namespace app\job;
use app\repository\AccountRepository;
use think\queue\Job;
class NotifySms
{
public function fire(Job $job, $data){
//短信通知列表
if ($data) {
foreach ($data as $item) {
echo sprintf("短信发送成功phone:%s time:%s \n", $item['mobile'], date('Y-m-d H:i:s'));
sleep(mt_rand(1,3));
}
}
// if ($job->attempts() > 3) {
// //通过这个方法可以检查这个任务已经重试了几次了
// echo sprintf('发送短信失败过多');
// }
//如果任务执行成功后 记得删除任务不然这个任务会重复执行直到达到最大重试次数后失败后执行failed方法
$job->delete();
// 也可以重新发布这个任务
// $job->release(3); //$delay为延迟时间
}
public function failed($data){
// ...任务达到最大重试次数后,失败了
}
}