I'm working with Laravel 9 Queue for the first time I'm looping over a CSV file and Inserting the data into the database every thing is in handle method in my Queue Class.
The Queue is working fine but sometimes returns Failed after X numbers of queries
I don't know what could be the reason. What can you suggest so I can Debug Please. I did all my best
Code :
public function handle()
{
$data = [];
$csv_data = Excel::toArray(new ContactsImport, $this->data['file']);
// takeoff the header
unset($csv_data[0][0]);
foreach($csv_data[0] as $rowKey => $rowValue){
foreach($this->data['fields'] as $key => $value){
if($value == 'emails'){
$emails = explode(',', $csv_data[0][$rowKey][$key]);
if(count($emails) > 1){
foreach($emails as $email){
$data['emails'][] = [
'value' => $email,
'label' => 'work'
];
}
}else{
$data['emails'] = [
[
'value' => $csv_data[0][$rowKey][$key],
'label' => 'work'
]
];
}
}else{
$data[$value] = $csv_data[0][$rowKey][$key];
}
}
$this->contactRepository->store(array_merge($data, ['entity_type' => 'persons']));
}
}
}
CodePudding user response:
So I found the solution, Job may need several minutes to complete. However workers by default will give every job 60 seconds to finish. we need to tell our workers to give us more time by doing php artisan queue:work --timeout=18000