2015-04-22 59 views
1

我正在制作一个使用Laravel 5的应用程序,此刻我遇到了一个小问题(我希望)。 所以我编码实现ShouldBeQueued像这样的命令:Laravel 5排队命令

class ImportDataCommand extends Command implements SelfHandling,ShouldBeQueued { 


    use InteractsWithQueue, SerializesModels; 

    public $filePath; 

    /** 
    * Create a new command instance. 
    * 
    * @return void 
    */ 
    public function __construct($filePath) 
    { 
     $this->filePath = $filePath; 
     Log::info('queued shit from command contructor and i have this destinationPath => '.$filePath);//working 
     echo "contructor ".$this->filePath; 

    } 

    /** 
    * Execute the command. 
    * 
    * @return void 
    */ 
    public function handle() 
    { 


     $destinationPath = storage_path().'/app/gtfs/'; 


     $zip = new ZipArchive; 
     echo "handle ".$this->filePath; 
     /*$res = $zip->open($destinationPath.$this->filePath); 
     if ($res === TRUE) { 
      $zip->extractTo($destinationPath.'extracted/'); 
      $zip->close(); 
      echo 'done'; 

     } else { 

      echo 'fail'; 

     }*/ 
    } 

} 

我打电话这样说:

$bus->dispatch(new ImportDataCommand($fileName)); 

时,在队列中(顺便说一句后执行命令我的问题是我使用beanstalkd)它引发异常,因为filePath没有设置,我想我已经明白了为什么会发生这种情况,当我用变量将它发送到busDispatcher上的队列时,该命令被实例化,但是当调用handle()时队列方面它没有发送。有什么建议么 ?

回答

1

最后我发现了兔子:我完全忘记了每次尝试冲洗所有作业,所以我不明白为什么,但它与命令混淆(iIhave重新启动了Vagrant机器,但我认为不会影响任何东西)。

1

您在构造函数中指定$this->filePath,然后在handle()方法中覆盖它。

+0

抱歉它是一个错字,现在固定 – danielgek

+0

如果我正好运行它,因为它是现在,我得到[Symfony的\分量\调试\异常\ FatalErrorException] 无法访问空属性 – danielgek

+0

你从哪里得到这个错误? –