3

I have been tearing my hair out this afternoon attempting to get job chaining to work. No matter what happens I cannot get a chained job to run. The first always runs and succeeds but the chained will never run.

For example I have an event listener like

  class PersistPreviousStatement implements ShouldQueue
    {
        /**
         * @param StatementCreated $event
         */
        public function handle(StatementCreated $event): void
        {
            DoOneThing::withChain([
                new DoSomething()
            ])->dispatch();
        }
}

My two job classes are below:

class DoOneThing
{
    use Dispatchable, Queueable;

    public function handle(): void
    {
        $statement = Statement::find(20);
        $statement->file = 'yyy';
        $statement->save();
    }
}


class DoSomething
{
    use Dispatchable, Queueable;

    public function handle(): void
    {
        $statement = Statement::find(10);
        $statement->file = 'xxxx';
        $statement->save();
    }
}

In the situation above. My DoOneThing class correctly sets the record with 'yyy' however the DoSomething class does not run. If I change the order like

DoSomething::withChain([
            new DoOneThing()
        ])->dispatch();

DoSomething is ran not DoOnething. I have both jobs set to queueable/Dispatchable and my driver is set to sync. I also can dispatch the jobs after each other independently like:

DoSomething::dispatch() DoOneThing::dispatch()

and both will run.

Any ideas?

Daniel Benzie
  • 479
  • 1
  • 5
  • 27
  • Do you not have to return true from the handle method for it to class as completed? – Joe Apr 02 '19 at 13:09

1 Answers1

1

I was missing the InteractsWithQueue trait in my jobs.

Daniel Benzie
  • 479
  • 1
  • 5
  • 27