Lucid Laravel将一个作业中的数据排队到另一个作业中 [英] Lucid Laravel Queue Data from one Job to another in chain

查看:99
本文介绍了Lucid Laravel将一个作业中的数据排队到另一个作业中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2个职位的队列:

   $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?

推荐答案

我仅通过查看代码库来链接作业.零文档在上面.通过进行一些研究,我发现贡献者具有已提交的工作链代码. 显然,如果需要链接工作,这是一个现实的问题,但是不能.

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.

我会使用另一个库来做.我发现了一个名为 guzzle/promises .

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();
}

这篇关于Lucid Laravel将一个作业中的数据排队到另一个作业中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆