laravel队列使用

1、修改.env中queue_driver = databases

2、php artisan queue:table 

  在database 目录下migrations里面有对应的表

3、执行迁移文件 php artisan migrate 

4、创建文件 php artisan make:job SendEmail

指定参数$email

class TestQu implements ShouldQueue
{
use InteractsWithQueue, Queueable, SerializesModels;
protected $email;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct($data)
{
$this->email = $data;
//
}

/**
* Execute the job.
*
* @return void
*/
public function handle()
{
file_put_contents("aaa.txt","ssss");
//
}
}

6、把任务放到队列中

在控制器中使用dispatch(new SendEmail('5555@qq.com'))

 指定存储队列名称

$job    =   new SendEmail($result['data']);
$job->onQueue("email");

7、运行监听器 php artisan queue:listen

 

8、支持失败记录php artisan queue:failed-table

9、执行迁移php artisan migrate 

10、查看失败记录php artisan queue:failed

11、从新执行失败的记录 php artisan queue:retry id编号

 php artisan queue:retry all执行全部

12、删除失败记录php artisan queue:forget id编号

删除全部用php arisan queue:flush

13、队列指定运行使用

php artisan queue:work redis --queue=email

 

ps:laravel swagger   https://github.com/DarkaOnLine/L5-Swagger

posted on 2018-09-09 18:43  我很迷茫  阅读(1594)  评论(0编辑  收藏  举报