【发布时间】:2015-06-04 05:25:48
【问题描述】:
我正在尝试使用命令,以便我可以将它们排队,因为一堆请求需要 30-90 秒才能完成。唯一的问题是该命令没有像我希望的那样将数据返回到我的控制器,相反,我得到的只是一个方便的(讽刺)“null”。这是我文件中的一些代码 sn-ps,感谢您的帮助!
家庭控制器
class HomeController extends Controller {
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Show the application dashboard to the user.
*
* @return Response
*/
public function index()
{
var_dump($this->dispatch(new \App\Commands\GetFeedCommand("http://alerts.weather.gov/cap/us.atom")));
}
GetFeedController
use App\Commands\Command;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldBeQueued;
use GuzzleHttp\Client;
class GetFeedCommand extends Command implements ShouldBeQueued {
use InteractsWithQueue, SerializesModels;
public $guzzle;
public $uri;
/**
* Create a new command instance.
*
* @return void
*/
public function __construct($uri)
{
$this->guzzle = new Client;
$this->uri = $uri;
}
}
GetFeedControllerHelper
use App\Commands\GetFeedCommand;
use Illuminate\Queue\InteractsWithQueue;
class GetFeedCommandHandler {
/**
* Create the command handler.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Handle the command.
*
* @param GetFeedCommand $command
* @return void
*/
public function handle(GetFeedCommand $command)
{
return $command->guzzle->get($command->uri)->xml();
}
}
任何帮助将不胜感激!谢谢!
【问题讨论】: