简体   繁体   English

Laravel 无法排队作业

[英]Laravel Unable to Queue Job

I repeatedly receive the following error when I try to push a job onto my Laravel Queue:当我尝试将作业推送到我的 Laravel 队列时,我反复收到以下错误:

Argument 1 passed to Illuminate\Queue\Jobs\Job::resolveAndFire() must be of the type array, null given, called in /home/vagrant/Code/project/vendor/laravel/framework/src/Illuminate/Queue/Jobs/BeanstalkdJob.php on line 53 and defined

I have no clue what is going wrong but I'm guessing it's something to do with the fact I haven't used the SerializesModel Trait?我不知道出了什么问题,但我猜这与我没有使用 SerializesModel Trait 这一事实有关? When I try to use Serializes model, I just get an undefined property $directory error.当我尝试使用 Serializes model 时,我只是收到一个未定义的属性 $directory 错误。

The job class is:工作 class 是:

/**
 * Class StoreFile
 * @package App\Jobs
 */
class StoreFile extends Job implements SelfHandling, ShouldQueue
{
    use InteractsWithQueue;

    /**
     * @param string $directory
     * @param string $filename
     * @param UploadedFile $file
     */
    public function __construct($directory, $filename, $file)
    {
        $this->directory = $directory;
        $this->filename = $filename;
        $this->file = $file;
    }

    /**
     * @param FileSystem $storage
     * @return boolean
     */
    public function handle(FileSystem $storage)
    {
        $path = $this->directory . $this->filename;
        $storage->disk('s3')->put($path, $this->file);

        return true;
    }
}

UPDATE I queue the job from another class using this:更新我使用这个从另一个 class 排队作业:

$this->dispatch(new StoreFile($directory, rawurlencode($filename), file_get_contents($evidence)));

Where $evidence is an UploadedFile.其中 $evidence 是一个 UploadedFile。 I'm certain that all the variables are set as if I remove the ShouldQueue/InteractsWithQueue the job executes fine我确定所有变量都设置为好像我删除了 ShouldQueue/InteractsWithQueue 作业执行正常

In my case, it was because the jobs tables was having a payload "0" instead of JSON for executing the job.在我的例子中,这是因为作业表有一个有效负载“0”而不是 JSON 来执行作业。

The error can be solved easy. 错误可以轻松解决。 Check: may be you added manualy test message to queue. 检查:可能是您将manualy测试消息添加到队列中。 So, this message can broke your code, because has another structure. 所以,这条消息可能会破坏你的代码,因为它有另一种结构。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM