wenus
wenus

Reputation: 1505

Lucid Laravel Queue Data from one Job to another in chain

I have a Queue with 2 JObs :

   $this->dispatch(new Test1Job())->chain(new Test2Job($here I want to have a paramter, which is returned from Test1Job));

How can I fetch data from one Job to another in queue?

Upvotes: 0

Views: 1823

Answers (1)

Jed Lynch
Jed Lynch

Reputation: 2156

I only chaining jobs from looking at the code base. There is zero documentation on it. From doing a little research I am seeing that contributors have committed code of job chaining. Obviously it is a real issue if need to chain jobs, but can't.

I would use another library to do it. I found one called guzzle/promises.

use Carbon\Carbon;
use GuzzleHttp\Promise\Promise;
use GuzzleHttp\Promise\EachPromise;

$job1 = (new JobClass1())->delay(Carbon::now()->addSeconds(5));
$job2 = (new JobClass2());
$job3 = (new JobClass3());
$job4 = (new JobClass4());

$promises = [dispatch($job1),dispatch($job2),dispatch($job3),dispatch($job4)];

$each = new EachPromise($promises, [
    'fulfilled' => function ($value, $id, Promise $aggregate) use (&$called) {
        $aggregate->resolve(null);
    },
    'rejected' => function (\Exception $reason) {
        echo $reason->getMessage();
    }
]);

$p = $each->promise();

foreach($p as $i => $prom){
    $prom->resolve();
    $prom->wait();
}

Upvotes: 1

Related Questions