问题
For dispatching a single job I usually do one of these:
Queue::push(new ExampleJob);
or
dispatch(new ExampleJob);
https://lumen.laravel.com/docs/5.5/queues
According to the Laravel Docs a certain Job chain, where one Job depends upon the previous is done like this:
ExampleJob::withChain([
new OptimizePodcast,
new ReleasePodcast
])->dispatch();
https://laravel.com/docs/5.5/queues#job-chaining
However this does not workin in Lumen (similar problem here: How to dispatch a Job to a specific queue in Lumen 5.5).
How do I chain Jobs in Lumen 5.5?
回答1:
I don't think that will work given that in Laravel 5.5 documentation, in their example under creating jobs under the Queues documentation page, it shows that it requires several traits to able use all the features:
<?php
namespace App\Jobs;
use App\Podcast;
use App\AudioProcessor;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
class ProcessPodcast implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
protected $podcast;
Most notably is this one:
use Illuminate\Foundation\Bus\Dispatchable;
which appears to be a trait that is missing from the Lumen 5.5 framework altogether.
The rest of the Illuminate\...
traits seem to be included.
来源:https://stackoverflow.com/questions/47308381/job-chaining-in-lumen-5-5-withchain-not-working-how-can-i-make-it-work