Diskon 50% terbatas! Masukkan kupon "programmer2025" di kelas apa saja

Menjalankan fungsi Symfon Process pada queued Jobs di laravel

halo semua. ada pertanyaan nih seputar fungsi  Symfon Process.  ane ada bikin jobs seperti ini

<?php

namespace App\Jobs;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;

use Symfony\Component\Process\Process;
use Symfony\Component\Process\Exception\ProcessFailedException;

class GetFB implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    public function __construct()
    {
        //
    }

    public function handle()
    {

        $csvFileName = public_path("csv/nintendo.csv");

        $process = new Process("facebook-scraper --filename ".$csvFileName." --pages 5 nintendo");
        $process->run();

        // executes after the command finishes
        if (!$process->isSuccessful()) {
            //execute failed code
        }else{
            //execute success code
        }
        $process->getOutput();
    }
}

ketika dijalankan. hasilnya false. tapi ketika prosess ini dijalankan di controller, fungsi process berhasil dijalankan.

bagaimana agar fungsi

new Process()

dapat dijalankan di Jobs. mohon bantuannya

avatar hiramakimen
@hiramakimen

3 Kontribusi 0 Poin

Diperbarui 4 tahun yang lalu

1 Jawaban:

<div>Setelah mencoba membaca di source code-nya, itu konstruktor sepertinya meminta parameter dalam bentuk array. Di dokumentasinya juga demikian.<br><br>Jadi mungkin bisa dicoba dulu yang seperti ini?</div><pre>new Process(["facebook-scraper", "--filename", $csvFileName, "--pages", "5", "nintendo"]);</pre><div><br>Cmiiw<br><br>Sumber:<br><a href="https://github.com/symfony/process/blob/240e74140d4d956265048f3025c0aecbbc302d54/Process.php#L133">https://github.com/symfony/process/blob/240e74140d4d956265048f3025c0aecbbc302d54/Process.php#L133</a><br><a href="https://symfony.com/doc/current/components/process.html#usage">https://symfony.com/doc/current/components/process.html#usage</a></div>

avatar kodergan
@kodergan

51 Kontribusi 58 Poin

Dipost 4 tahun yang lalu

Login untuk ikut Jawaban