dqtiober37522 2017-06-11 08:04
浏览 281
已采纳

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 08: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条)

报告相同问题?

悬赏问题

  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 用matlab 设计一个不动点迭代法求解非线性方程组的代码
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug