目前我正在尝试在后台运行一个事件并将其排队。运行后,我想播放输出。
在我的app / Events /文件夹中,我有一个类(监听器)EventsSynchronised看起来像这样:
class EventsSynchronised extends Event implements ShouldBroadcast, ShouldQueue
{
use SerializesModels;
use InteractsWithQueue;
public function __construct( )
{
Log::info('ES constructor');
}
/**
* Get the channels the event should be broadcast on.
*
* @return array
*/
public function broadcastOn()
{
return [ 'test-channel' ];
}
}
我有一个处理程序,需要在调用侦听器后完成:
class HandleInput
{
public function __construct()
{
}
public function handle( EventsSynchronised $event )
{
Log::info('HI handle()');
}
}
所以现在我需要将它们注册到EventServiceProvider
class EventServiceProvider extends ServiceProvider
{
/**
* The event listener mappings for the application.
*
* @var array
*/
protected $listen = [
EventsSynchronised::class => [
HandleInput::class
],
];
/**
* Register any other events for your application.
*
* @param \Illuminate\Contracts\Events\Dispatcher $events
* @return void
*/
public function boot( DispatcherContract $events )
{
parent::boot( $events );
//
}
}
在准备好所有内容后,我添加了一条测试路线:
Route::get( 'send', function ()
{
Event::fire( new EventsSynchronised() );
} );
如果HandleInput :: class被立即调用而没有排队,会怎样才能解决这个问题?我也试过$ this-> release(60)来保持一分钟。