kyawkyawsoezhu's avatar

workflow for large export CSV in background

I want to know how Even, Job, Queue and Sync work in Laravel 5.3, currently I convert collection to csv and save to s3 like this,

        $captures = $this->getCaptures(. . .)->getCollection();
        $csv = \League\Csv\Writer::createFromFileObject(new \SplTempFileObject());
        $csv->insertOne(array_keys($captures->first()));
        $captures->map(function ($item) use ($csv) {
            return $csv->insertOne($item);
        });

        $filePath = . . .;
        $fileName = . . . ;

        $s3 = \Storage::disk('s3');
        $s3->put($filePath . $fileName, $csv->__toString(), 'public');
        return $s3->url($filePath . $fileName);

but later I will have to export large amount of csv that why I want to run the job in the background after job finished or error occur send notification email to user.

sorry for my poor English :(

0 likes
2 replies
kyawkyawsoezhu's avatar

Thank @richard It make me more understand,

and let me explain a bit more about my app, user will use the app capture (scan) each other to get information and save to the database, after that they will export all user they have captured by click export button, my question is it's the right way to use queues and event, or do you have some post that explain something similar like my situation .

Please or to participate in this conversation.