【发布时间】:2015-06-30 12:36:26
【问题描述】:
我正在使用 Laravel 5 制作应用程序,目前我遇到了一个小问题(我希望如此)。 所以我编写了一个像这样实现 ShouldBeQueued 的命令:
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() 时,它不会发送该命令。有什么建议吗?
【问题讨论】:
标签: php laravel command queue laravel-5