canyin-project/ybcy/jobs/ImportUserJob.php

41 lines
1.1 KiB
PHP
Raw Permalink Normal View History

2024-11-01 16:07:54 +08:00
<?php
namespace app\jobs;
use yii;
use yii\base\BaseObject;
use yii\queue\RetryableJobInterface;
class ImportUserJob extends BaseObject implements RetryableJobInterface
{
public $data;
public function __construct($data)
{
$this->data = $data;
return $this;
}
//处理单个任务的最大时间
public function getTtr()
{
return 2;
}
//任务超时超过getTtr配置的时间 重复 加入队列 的次数 $attempt
public function canRetry($attempt, $error)
{
return ($attempt < 3) && ($error);
}
//执行队列
public function execute($queue)
{
$data = $this->data;
date_default_timezone_set('PRC');
Yii::$app->mailer->compose('layouts/login', [
'dateTime' => date('Y-m-d H:i:s'),
'h2' => $data['name'],
'h3' => $data['id'],
'pushDate' => $data['pushDate'],
'code' => 0,
'msg' => 'OK'
])
->setTo('123456789@qq.com')
->setSubject('发送用户请求信息')
->send();
}
}