please help, I might be doing or understood something wrong. I am creating a mass upload to database, which takes a little bit of time so I decided to make async all and proccess it in background using Laravel Queues.
In controller I create an associated list, which is passed to Laravel Job.
foreach($data as $row)
{
$instantArray = array();
$orderDate = \PHPExcel_Shared_Date::ExcelToPHPObject($row[3]);
$issueDate = \PHPExcel_Shared_Date::ExcelToPHPObject($row[4]);
$orderRow = array(
'invoice_no' => trim($row[0]),
'agent_id' => $row[1],
'issued_at' => $orderDate->format('Y-m-d'),
'received_at' => $issueDate->format('Y-m-d'),
);
$gameArray = array();
$invoiceOrdersArray[] = $orderRow;
}
$job = (new Import($invoiceOrdersArray));
dispatch($job);
In Laravel Job I am trying to create an entyty and upload it to database
class Import implements ShouldQueue
{
use InteractsWithQueue, SerializesModels, Queueable, Dispatchable;
protected $importData;
public function __construct($importData)
{
$this->importData = $importData;
}
public function handle()
{
foreach($invoiceOrdersArray as $insert)
{
$order = InvoicesOrder::create($insert);
}
}
However, every time I am trying I can see in my logs:
#0 app\Utilities\Updater.php(18): Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(8, 'Trying to get p...', '...', 18, Array)
#1 vendor\laravel\framework\src\Illuminate\Events\Dispatcher.php(348): Modules\Accounting\Entities\InvoicesOrder::App\Utilities\{closure}(Object(Modules\Accounting\Entities\InvoicesOrder))
#2 vendor\laravel\framework\src\Illuminate\Events\Dispatcher.php(199): Illuminate\Events\Dispatcher->Illuminate\Events\{closure}('eloquent.creati...', Array)
#3 vendor\laravel\framework\src\Illuminate\Events\Dispatcher.php(159): Illuminate\Events\Dispatcher->dispatch('eloquent.creati...', Array, true)
#4 vendor\laravel\framework\src\Illuminate\Database\Eloquent\Concerns\HasEvents.php(148): Illuminate\Events\Dispatcher->until('eloquent.creati...', Object(Modules\Accounting\Entities\InvoicesOrder))
#5 vendor\laravel\framework\src\Illuminate\Database\Eloquent\Model.php(636): Illuminate\Database\Eloquent\Model->fireModelEvent('creating')
#6 vendor\laravel\framework\src\Illuminate\Database\Eloquent\Model.php(522): Illuminate\Database\Eloquent\Model->performInsert(Object(Illuminate\Database\Eloquent\Builder))
#7 Modules\Accounting\Jobs\ImportFiles.php(39): Illuminate\Database\Eloquent\Model->save()
#8 [internal function]: Modules\Accounting\Jobs\ImportFiles->handle()
#9 vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php(29): call_user_func_array(Array, Array)
#10 vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php(87): Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()
#11 vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php(31): Illuminate\Container\BoundMethod::callBoundMethod(Object(Illuminate\Foundation\Application), Array, Object(Closure))
#12 vendor\laravel\framework\src\Illuminate\Container\Container.php(539): Illuminate\Container\BoundMethod::call(Object(Illuminate\Foundation\Application), Array, Array, NULL)
#13 vendor\laravel\framework\src\Illuminate\Bus\Dispatcher.php(94): Illuminate\Container\Container->call(Array)
#14 vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(114): Illuminate\Bus\Dispatcher->Illuminate\Bus\{closure}(Object(Modules\Accounting\Jobs\ImportFiles))
#15 vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(102): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Modules\Accounting\Jobs\ImportFiles))
#16 vendor\laravel\framework\src\Illuminate\Bus\Dispatcher.php(98): Illuminate\Pipeline\Pipeline->then(Object(Closure))
#17 vendor\laravel\framework\src\Illuminate\Queue\CallQueuedHandler.php(42): Illuminate\Bus\Dispatcher->dispatchNow(Object(Modules\Accounting\Jobs\ImportFiles), false)
#18 vendor\laravel\framework\src\Illuminate\Queue\Jobs\Job.php(69): Illuminate\Queue\CallQueuedHandler->call(Object(Illuminate\Queue\Jobs\RedisJob), Array)
#19 vendor\laravel\framework\src\Illuminate\Queue\Worker.php(317): Illuminate\Queue\Jobs\Job->fire()
Whenever I do it in controller it works fine, it just loads very long. Maybe it is not possible to save entities in Job using queues?
Thank you.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire