Hello
I need to create timer in Laravel8, in backend side for processing,
Api request 3rd party.
They have limited API to 150 request per minutes.
I am processing incoming data from cvs file and file can contain 100k rows, but only one column.
-> I am creating chunk for each 1k rows.
$chunks = array_chunk($data, 1000);
- after that run via foreach.
foreach ($chunks as $key => $chunk){
-> and dispatch them to job queue.
dispatch(new SaveDataJob($chunk, $businessIds));
-> which creates queue job for model PrhList::saveData
-> which pass it back other foreach.
-> which include other dispatch for sending request to API endpoint.
My model
public static function processData($data)
{
unset($data[0]);
$chunks = array_chunk($data, 1000);
$pathname = 'tmp-data';
$files = array();
foreach ($chunks as $key => $chunk){
$name = "/tmp{$key}.cvs";
$path = $pathname.$name;
$businessIds = array();
dispatch(new SaveDataJob($chunk, $businessIds));
} // end of outter foreach loop //
and other function:
public static function saveData($chunk, $businessIds)
{
foreach ($chunk as $row){
$data = implode(" ",$row);
$demitter = '; ' ;
array_push($businessIds, $data, $demitter );
// Save to DB
PrhList::updateOrCreate([
'business_id' => $data,
]);
$businessId = $data;
dispatch(new SearchByBusinessId($businessId ));
} // end of inner foreach loop //
Q) I need to count how many request I have sent to API.
I have tried $count = $chunk->count();
but that works only for collection, I am using array.
I am getting error:
"Error: Call to a member function count()
on int"
Thanks MikroMike