laravel 作业/队列未处理怪异的无限循环
laravel Job / Queue not been processed weird infinite loop
我正在尝试创建一个队列,但是当我 运行 php artisan queue:work
我在终端中得到的只是
时它不起作用
[2017-11-30 19:56:27] Processing: App\Jobs\ProcessCSV
[2017-11-30 19:56:27] Processing: App\Jobs\ProcessCSV
[2017-11-30 19:56:27] Processing: App\Jobs\ProcessCSV
[2017-11-30 19:56:27] Processing: App\Jobs\ProcessCSV
[2017-11-30 19:56:27] Processing: App\Jobs\ProcessCSV
[2017-11-30 19:56:27] Processing: App\Jobs\ProcessCSV
[2017-11-30 19:56:27] Processing: App\Jobs\ProcessCSV
[2017-11-30 19:56:27] Processing: App\Jobs\ProcessCSV
[2017-11-30 19:56:27] Processing: App\Jobs\ProcessCSV
[2017-11-30 19:56:27] Processing: App\Jobs\ProcessCSV
这就像一个无限循环。我的工作 table 中的 id 也在不断上升。它确实可以在我的笔记本电脑上运行,但不能在我的台式机上运行,这很奇怪。我把它放到了我的开发服务器上,但它在那里也不起作用。
我的代码如下,如有任何帮助,我们将不胜感激。
控制器
public function upload(Request $request) {
if($request->file('imported-file')) {
$user = "craig@boldy.co.uk";
$file = $request->file('imported-file')->store('uploads', 'public');
$this->dispatch(new ProcessCSV($file, $user));
Session::flash('success', 'Your file was uploaded successfully. We will email you once the locations have be imported.');
return back();
} else {
Session::flash('error', 'Please select a file to upload!!!!');
return back();
}
}
工作
public function handle()
{
$data = Excel::load($this->file, function($reader) {})->get();
$apiKey = '';
foreach($data as $row) {
if(!empty($row['postcode'])) {
$url = "https://maps.googleapis.com/maps/api/geocode/xml?address=".urlencode($row['postcode'])."®ion=uk&key=";
$tmp = file_get_contents($url);
$xml = simplexml_load_string($tmp);
// print_r($xml); exit;
if((string)$xml->status == 'OK' && isset($xml->result[0])) {
if(isset($xml->result[0]->geometry->location->lat)) {
$lat = (string)$xml->result[0]->geometry->location->lat;
}
if(isset($xml->result[0]->geometry->location->lng)) {
$lng = (string)$xml->result[0]->geometry->location->lng;
}
}
Import::updateOrCreate(
[
'sitecode' => $row['sitecode']
],
[
'sitecode' => $row['sitecode'],
'sitename' => $row['sitename'],
'address_1' => $row['address_1'],
'address_2' => $row['address_2'],
'address_town' => $row['address_town'],
'address_postcode' => $row['postcode'],
'charity' => $row['charity'],
'latitude' => $lat,
'longitude' => $lng,
'approved' => 1
]
);
}
}
}
而不是 php artisan queue:work
..您需要添加选项参数 --tries
以避免无限循环.. 如果工作中发生错误,通常会发生这种情况。如果使用驱动程序数据库,请参阅 laravel.log 或 failed-job table。它会显示错误
php artisan queue:work --tries=3
我正在尝试创建一个队列,但是当我 运行 php artisan queue:work
我在终端中得到的只是
[2017-11-30 19:56:27] Processing: App\Jobs\ProcessCSV
[2017-11-30 19:56:27] Processing: App\Jobs\ProcessCSV
[2017-11-30 19:56:27] Processing: App\Jobs\ProcessCSV
[2017-11-30 19:56:27] Processing: App\Jobs\ProcessCSV
[2017-11-30 19:56:27] Processing: App\Jobs\ProcessCSV
[2017-11-30 19:56:27] Processing: App\Jobs\ProcessCSV
[2017-11-30 19:56:27] Processing: App\Jobs\ProcessCSV
[2017-11-30 19:56:27] Processing: App\Jobs\ProcessCSV
[2017-11-30 19:56:27] Processing: App\Jobs\ProcessCSV
[2017-11-30 19:56:27] Processing: App\Jobs\ProcessCSV
这就像一个无限循环。我的工作 table 中的 id 也在不断上升。它确实可以在我的笔记本电脑上运行,但不能在我的台式机上运行,这很奇怪。我把它放到了我的开发服务器上,但它在那里也不起作用。
我的代码如下,如有任何帮助,我们将不胜感激。
控制器
public function upload(Request $request) {
if($request->file('imported-file')) {
$user = "craig@boldy.co.uk";
$file = $request->file('imported-file')->store('uploads', 'public');
$this->dispatch(new ProcessCSV($file, $user));
Session::flash('success', 'Your file was uploaded successfully. We will email you once the locations have be imported.');
return back();
} else {
Session::flash('error', 'Please select a file to upload!!!!');
return back();
}
}
工作
public function handle()
{
$data = Excel::load($this->file, function($reader) {})->get();
$apiKey = '';
foreach($data as $row) {
if(!empty($row['postcode'])) {
$url = "https://maps.googleapis.com/maps/api/geocode/xml?address=".urlencode($row['postcode'])."®ion=uk&key=";
$tmp = file_get_contents($url);
$xml = simplexml_load_string($tmp);
// print_r($xml); exit;
if((string)$xml->status == 'OK' && isset($xml->result[0])) {
if(isset($xml->result[0]->geometry->location->lat)) {
$lat = (string)$xml->result[0]->geometry->location->lat;
}
if(isset($xml->result[0]->geometry->location->lng)) {
$lng = (string)$xml->result[0]->geometry->location->lng;
}
}
Import::updateOrCreate(
[
'sitecode' => $row['sitecode']
],
[
'sitecode' => $row['sitecode'],
'sitename' => $row['sitename'],
'address_1' => $row['address_1'],
'address_2' => $row['address_2'],
'address_town' => $row['address_town'],
'address_postcode' => $row['postcode'],
'charity' => $row['charity'],
'latitude' => $lat,
'longitude' => $lng,
'approved' => 1
]
);
}
}
}
而不是 php artisan queue:work
..您需要添加选项参数 --tries
以避免无限循环.. 如果工作中发生错误,通常会发生这种情况。如果使用驱动程序数据库,请参阅 laravel.log 或 failed-job table。它会显示错误
php artisan queue:work --tries=3