Home  >  Article  >  Backend Development  >  Laravel数据库队列倒序怎么执行

Laravel数据库队列倒序怎么执行

PHPz
PHPzOriginal
2016-06-06 20:29:112332browse

Laravel数据库队列倒序的执行方法:首先查看文件路径“Illuminate\Queue”;然后找到代码“orderBy('id', 'asc')”;最后直接把参数“asc”改成“desc”即可。

Laravel数据库队列倒序怎么执行

Laravel 数据库队列倒序怎么执行?

Laravel 数据库队列倒序执行

要实现的结果

f6a985e2e15b1c32c74de6a928bec63.png

laravel 是 101810 101811 101812 ....101819 这样执行的

如果我们想要他 101819 101817 101816 101815 这样倒序执行

看下源码

文件路径:

namespace Illuminate\Queue;
Class DatabaseQueue
protected function getNextAvailableJob($queue)\
{
  $job = $this->database->table($this->table)\
 ->lockForUpdate()\ ->where('queue', $this->getQueue($queue))\
 ->where(function ($query) {
  $this->isAvailable($query);
  $this->isReservedButExpired($query);
 }) ->orderBy('id', 'asc')
 ->first();
}

这是laravel获取下一个队列的方法

我们可以直接把asc改成desc

效果图

f380a496473bda3e8d0699c8ed212b8.png

5aef01be6ac13f19e1478b74248145a.png

我遇到的

因为采集小说10w本  每本都是一个队列(采集章节  平均300章)
1本(300章)要30秒     
24小时采集10w*300 /30/ 86400都要11天了  (我估计要15天)
所以本地从队列从1 2 3 4 5 6开始执行
服务器就从10w 10w-1 10w-2  倒序执行
最后合并章节
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn