ジョブで LARAVEL キューを使用してデータベースに大きな Excel を挿入していますが、いくつかのジョブが詰まって実行されていません。
ファイルの内容(ジョブごとに250行)をチャンクし、停止するまでほとんどの内容を挿入します。
コードの挿入 (250 行以下を挿入するジョブ)
public function handle()
{
$uuid = Uuid::generate(4);
$defaultsSize = 0;
$customSize = 0;
$defaultsIdFields = [];
$customFields = [];
if (sizeof($this->matrixDefaultFields) > 0) {
$defaultsSize = sizeof($this->matrixDefaultFields[0][0]); //size of one of the vecs in default values
$defaultsIdFields = $this->matrixDefaultFields[0][0]; // all default fields id
}
if (sizeof($this->matrixCustomFields) > 0) {
$customSize = sizeof($this->matrixCustomFields[0][0]); //sizeof one of the vecs in custom values
$customFields = $this->matrixCustomFields[0][0]; // all custom fields id
}
for ($i = 0; $i < sizeof($this->matrixContacts); $i++) {
$contact = Contact::create(['UUID' => $uuid, 'id_contact_list' => $this->matrixContacts[$i][1],
'nome' => $this->matrixContacts[$i][2], 'email' => $this->matrixContacts[$i][3], 'unsub_code' => $this->matrixContacts[$i][4]]);
for ($j = 0; $j < $defaultsSize; $j++) {
$defaultsValuesFields = $this->matrixDefaultFields[$i][1]; //field value
CompanyListFieldValues::create(['company_id' => $this->idCompany,
'contact_id' => $contact->id,
'field_id' => $defaultsIdFields[$j],
'isDefault' => 1,
'value' => $defaultsValuesFields[$j]]);
}
for ($k = 0; $k < $customSize; $k++) {
$customValuesFields = $this->matrixCustomFields[$i][1]; //field value
CompanyListFieldValues::create(['company_id' => $this->idCompany,
'contact_id' => $contact->id,
'field_id' => $customFields[$k],
'isDefault' => 0,
'value' => $customValuesFields[$j]]);
}
}
}
ジョブのジェネレーターからのコード (これは正常に動作します)
for ($row = $this->startFrom; $row <= $highestRow; $row++) {
if ($rowMatrix == $chunksize) {
// $job = (new importExcelInsert($matrixContacts, $matrixDefaultFields, $matrixCustomFields, $this->idCompany))->delay($jobDelay)->onQueue('excelInserts');
// var_dump($matrixContacts);
$job = (new importExcelInsert($matrixContacts, $matrixDefaultFields, $matrixCustomFields, $this->idCompany, $rowMatrix))->delay($jobDelay)->onQueue('excelInserts');
$this->dispatch($job);
$njobs++;
$matrixContacts = [];
$matrixDefaultFields = [];
$matrixCustomFields = [];
$rowMatrix = 0;
}
$userEmail = $sheet->getCellByColumnAndRow($posEmail, $row)->getValue();
if ($userEmail == '' || !filter_var($userEmail, FILTER_VALIDATE_EMAIL)) {
$error++;
} else if (Contact::where('email', '=', $userEmail)->where('id_contact_list', '=', $this->idList)->count()) {
$ignored++;
} else {
// $uuid = Uuid::generate(4);
$matrixContacts[$rowMatrix][1] = $this->idList; //CONTACT_LIST_ID
$matrixContacts[$rowMatrix][2] = $sheet->getCellByColumnAndRow($posNome, $row)->getValue(); //Name
$matrixContacts[$rowMatrix][3] = $userEmail; //Email
$matrixContacts[$rowMatrix][4] = $unsubCode; //Unsubscribe Code
$vecFieldId = [];
$vecValues = [];
$i = 0;
if (!$this->arrayDefaultFields[0] == null) {
for ($j = 0; $j < sizeof($this->arrayDefaultFields); $j += 2) {
$vecFieldId[$i] = $this->arrayDefaultFields[$j];
$vecValues[$i] = $sheet->getCellByColumnAndRow($this->arrayDefaultFields[$j + 1], $row)->getValue();
$i++;
}
$matrixDefaultFields[$rowMatrix][0] = $vecFieldId;
$matrixDefaultFields[$rowMatrix][1] = $vecValues;
}
$i = 0;
if (!$this->arrayCustomFields[0] == null) {
for ($j = 0; $j < sizeof($this->arrayCustomFields); $j += 2) {
$vecFieldId[$i] = $this->arrayCustomFields[$j];
$vecValues[$i] = $sheet->getCellByColumnAndRow($this->arrayCustomFields[$j + 1], $row)->getValue();
$i++;
}
$matrixCustomFields[$rowMatrix][0] = $vecFieldId;
$matrixCustomFields[$rowMatrix][1] = $vecValues;
}
$rowMatrix++;
}
}
if (!empty($matrixContacts)) {
$job = (new importExcelInsert($matrixContacts, $matrixDefaultFields, $matrixCustomFields, $this->idCompany, $rowMatrix + 1))->delay($jobDelay)->onQueue('excelInserts');
$this->dispatch($job);
$njobs++;
}