Lumen Database Queued Event Listener 事件消失
Lumen Database Queued Event Listener event disappears
根据 Laravel 事件文档,我的印象是我可以通过在侦听器上添加 "implements ShouldQueue" 来异步创建事件队列。
namespace App\Listeners;
use Log;
use App\Events\MeetEntryConfirmationEvent;
use App\Mail\MeetEntryConfirmation;
use Illuminate\Contracts\Queue\ShouldQueue;
class MeetEntryConfirmationListener implements ShouldQueue
{
/**
* Create the event listener.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Handle the event.
*
* @param MeetEntryConfirmationEvent $event
* @return void
*/
public function handle(MeetEntryConfirmationEvent $entryEvent)
{
Log::debug('Attempt to send MeetEntryConfirmationEvent');
// Do time consuming stuff
}
}
我的活动是这样执行的:
class MeetEntryConfirmationEvent extends Event
{
use SerializesModels;
public $entry;
/**
* Create a new event instance.
*
* @return void
*/
public function __construct(MeetEntry $entry)
{
$this->entry = $entry;
Log::debug('Created MeetEntryConfirmationEvent');
}
}
我就是这样派遣他们的。
event(new MeetEntryConfirmationEvent($entry));
我已经将 QUEUE_DRIVER 设置为数据库,作业 table 就在那里。当事件被调度时,它似乎工作正常,因为它立即 returns。当我在同步模式下使用它时,该作业需要 8 秒,因此不再发生这种情况。
然而,作业 table 永远不会在其中获得一行,并且当我 运行 队列工作程序没有任何反应时,作业不会执行。
我也尝试将 config/queue.php 从 Laravel 复制到我的 lumen 应用程序中,但这似乎没有什么不同。当它在同步驱动程序中并且当我没有使用 ShouldQueue 时,这项工作确实曾经发生过。
所以我最终找到了问题所在。它归结为 Lumen/Laravel 手册中没有的细节。
您需要将此添加到服务提供商注册部分的 Lumen bootstrap:
$app->configure('queue');
$app->register(Illuminate\Queue\QueueServiceProvider::class);
根据 Laravel 事件文档,我的印象是我可以通过在侦听器上添加 "implements ShouldQueue" 来异步创建事件队列。
namespace App\Listeners;
use Log;
use App\Events\MeetEntryConfirmationEvent;
use App\Mail\MeetEntryConfirmation;
use Illuminate\Contracts\Queue\ShouldQueue;
class MeetEntryConfirmationListener implements ShouldQueue
{
/**
* Create the event listener.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Handle the event.
*
* @param MeetEntryConfirmationEvent $event
* @return void
*/
public function handle(MeetEntryConfirmationEvent $entryEvent)
{
Log::debug('Attempt to send MeetEntryConfirmationEvent');
// Do time consuming stuff
}
}
我的活动是这样执行的:
class MeetEntryConfirmationEvent extends Event
{
use SerializesModels;
public $entry;
/**
* Create a new event instance.
*
* @return void
*/
public function __construct(MeetEntry $entry)
{
$this->entry = $entry;
Log::debug('Created MeetEntryConfirmationEvent');
}
}
我就是这样派遣他们的。
event(new MeetEntryConfirmationEvent($entry));
我已经将 QUEUE_DRIVER 设置为数据库,作业 table 就在那里。当事件被调度时,它似乎工作正常,因为它立即 returns。当我在同步模式下使用它时,该作业需要 8 秒,因此不再发生这种情况。
然而,作业 table 永远不会在其中获得一行,并且当我 运行 队列工作程序没有任何反应时,作业不会执行。
我也尝试将 config/queue.php 从 Laravel 复制到我的 lumen 应用程序中,但这似乎没有什么不同。当它在同步驱动程序中并且当我没有使用 ShouldQueue 时,这项工作确实曾经发生过。
所以我最终找到了问题所在。它归结为 Lumen/Laravel 手册中没有的细节。
您需要将此添加到服务提供商注册部分的 Lumen bootstrap:
$app->configure('queue');
$app->register(Illuminate\Queue\QueueServiceProvider::class);