Laravel无法排队作业。

3

当我尝试将作业推到我的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

我不知道出了什么问题,但我猜想这可能与我没有使用SerializesModel Trait有关。当我尝试使用Serializes model时,我只得到了一个未定义的属性$directory错误。

作业类是:

/**
 * 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;
    }
}

更新 我使用以下方式从另一个类中排队作业:

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

当 $evidence 是一个 UploadedFile 时。我确信如果我移除 ShouldQueue/InteractsWithQueue,所有变量都被设置正确,任务可以正常执行。


为什么不发布导致错误的代码?你如何调用这个任务?$directory设置了吗?为什么要返回true? - baao
从错误看起来,似乎是在排队作业时发生了问题,请发布一些代码片段,展示您如何排队作业。 - yangqi
谢谢帮忙,我已经更新了我的问题。还有不知道为什么返回true,可能是个意外。 - ExoticChimp
@ExoticChimp,你解决了这个问题吗?我有类似的问题,你能在这里做出贡献吗:http://stackoverflow.com/questions/33917028/undefined-property-illuminate-queue-jobs-beanstalkdjob-name - ikuchris
你有没有解决那个问题的运气?我也遇到了同样的问题。 - Ahmad Hajjar
@yangqi 在我的情况下,当Worker.php尝试执行作业时会出现这种情况,在调试中我发现作业原始数据在进行json_decoded时意外地导致了“空字符串”,令人惊讶的是,这意味着原始数据不是有效的json,这引发了一个问题,beanstalk首先如何接受它,或者laravel如何添加它!! - Ahmad Hajjar
2个回答

0
在我的情况下,这是因为作业表具有负载“0”,而不是用于执行作业的JSON。

-4
错误可以很容易地解决。请检查:您是否手动将测试消息添加到队列中。因此,此消息可能会破坏您的代码,因为它具有另一种结构。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接