dqtiober37522 2017-06-11 00:04
浏览 282
已采纳

Laravel作业在队列中多次执行

Hi I have a laravel job as follows:

namespace App\Jobs;

use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;

use Timeline\Timeline;

class testQueue implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle(Timeline $timeline, $tag)
    {
        $tagData = $timeline->getTagFeed($tag)->getRankedItems();

        if ($tagData) {
            echo "boom";
        }    
    }
}

I'm running it via a route as follows:

Route::get('/queue', function () {
    $timeline= new Timeline();

    $timeline->login("test", "testpwd");
    Queue::later(5, new testQueue($timeline, "Testtag"));
});

Then on the commandline I ran:

php artisan queue:listen database

However, that one job is running 255 times instead of 1 times and exiting successfully.

What am I doing wrong?

展开全部

  • 写回答

2条回答 默认 最新

  • doupike2351 2017-06-11 00:33
    关注

    The documentation states:

    Binary data, such as raw image contents, should be passed through the base64_encode function before being passed to a queued job. Otherwise, the job may not properly serialize to JSON when being placed on the queue.

    So you shouldn't use public function handle(Timeline $timeline, $tag) (or public function handle(Instagram $currentInstagram, $tag) in your conversation, as the Timeline or something is binary data.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部