Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/232.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在laravel中存储队列中已处理的作业_Php_Laravel - Fatal编程技术网

Php 在laravel中存储队列中已处理的作业

Php 在laravel中存储队列中已处理的作业,php,laravel,Php,Laravel,我正在处理队列,试图找到一种方法,将处理过的作业记录在“已处理的作业”表中,就像失败的作业存储在“失败的作业”表中一样,这会自动发生。我正在使用“数据库”进行队列连接。我尝试了两种不同的方法。首先,我尝试在另一个命令文件“WorkerCommand”中扩展WorkCommand(“Lightlight\Queue\Console\WorkCommand”) <?php namespace App\Console\Commands; use Illuminate\Queue\Consol

我正在处理队列,试图找到一种方法,将处理过的作业记录在“已处理的作业”表中,就像失败的作业存储在“失败的作业”表中一样,这会自动发生。我正在使用“数据库”进行队列连接。我尝试了两种不同的方法。首先,我尝试在另一个命令文件“WorkerCommand”中扩展WorkCommand(“Lightlight\Queue\Console\WorkCommand”)

<?php

namespace App\Console\Commands;

use Illuminate\Queue\Console\WorkCommand;
use Illuminate\Contracts\Cache\Repository as Cache;
use Illuminate\Queue\Worker;
use Illuminate\Queue\Events\JobFailed;
use Illuminate\Queue\Events\JobProcessed;
use Illuminate\Queue\Events\JobProcessing;

class WorkerCommand extends WorkCommand
{
   protected function listenForEvents()
    {
        $this->laravel['events']->listen(JobProcessing::class, function ($event) {
            $this->writeOutput($event->job, 'starting');
        });

        $this->laravel['events']->listen(JobProcessed::class, function ($event) {
            $this->writeOutput($event->job, 'success');

            \DB::table('processed_jobs')->insert([
               'connection' => $event->connectionName,
               'queue' => $event->job->getQueue(),
               'payload' => $event->job->payload(),
               'processed_at' => \Carbon\Carbon::Now()
            ]);
        });

        $this->laravel['events']->listen(JobFailed::class, function ($event) {
            $this->writeOutput($event->job, 'failed');

            $this->logFailedJob($event);
        });
    }
}
这也没用。我找不到别的东西了。提前谢谢。 以下是作业文件:

<?php

namespace App\Jobs;

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

class ProcessSleep 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()
    {
        sleep(10);
    }
}

这是因为“processed_jobs”表中的“payload”列是长文本的,但
$event->job->payload
返回的是对象。因此,我使用json_encode修复了它

public function boot()
{
    Queue::after(function (JobProcessed $event) {
        \DB::table('processed_jobs')->insert([
           'connection' => $event->connectionName,
           'queue' => $event->job->getQueue(),
           'payload' => json_encode($event->job->payload()),
           'processed_at' => \Carbon\Carbon::Now()
        ]);
    });
}

这是因为“processed_jobs”表中的“payload”列是长文本的,但
$event->job->payload
返回的是对象。因此,我使用json_encode修复了它

public function boot()
{
    Queue::after(function (JobProcessed $event) {
        \DB::table('processed_jobs')->insert([
           'connection' => $event->connectionName,
           'queue' => $event->job->getQueue(),
           'payload' => json_encode($event->job->payload()),
           'processed_at' => \Carbon\Carbon::Now()
        ]);
    });
}

您遇到了什么样的错误?在AppServiceProvider中,进行日志调用以检查您的信息是否已到达。就在插入日志::info([//事件])之前;我发现了问题。这是因为表中的“payload”列是longtext,但
$event->job->payload
正在返回对象。谢谢。你遇到了什么样的错误?在你的AppServiceProvider中,打一个日志电话检查你的信息是否到达那里。就在插入日志::info([//事件])之前;我发现了问题。这是因为表中的“payload”列是longtext,但
$event->job->payload
正在返回对象。谢谢
public function boot()
{
    Queue::after(function (JobProcessed $event) {
        \DB::table('processed_jobs')->insert([
           'connection' => $event->connectionName,
           'queue' => $event->job->getQueue(),
           'payload' => json_encode($event->job->payload()),
           'processed_at' => \Carbon\Carbon::Now()
        ]);
    });
}