skip to Main Content

Is there any way to pass the return value of a job to the next job in the chain, or is there another easy way to pass data to the next job? Otherwise I would create a UUID beforehand and pass it to the jobs as a parameter, which they use to access a shared memory.

use AppJobsFirstJob;
use AppJobsSecondJob;
use AppJobsThirdJob;
use IlluminateSupportFacadesBus;
 
Bus::chain([
    new FirstJob,
    new SecondJob,
    new ThirdJob,
])->dispatch();

2

Answers


  1. You can pass data between jobs in a chain using the withChain() method.

    use AppJobsFirstJob;
    use AppJobsSecondJob;
    use AppJobsThirdJob;
    use IlluminateSupportFacadesBus;
    
    $data = ['key' => 'value'];
    
    Bus::chain([
        new FirstJob,
        new SecondJob,
        new ThirdJob,
    ])->withChain([
        new FirstJob($data), 
        new SecondJob($data),
    ])->dispatch();
    
    Login or Signup to reply.
  2. Definitely without the withChain method should work. But you have to address retries and timeout.

            Bus::chain([
                new OnlyofficeProcessJob($spreadsheet, $key),
                new OnlyofficeDocumentJob,
                function () {
                    ds('will run after finishing');
                    // dispatch(new OnlyofficeDocumentJob) -> this though will not work;
                    // Podcast::update(/* ... */);
                },
            ])
            ->dispatch();
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search