diegowazevedo/laravel-database-queue

0.6.1 2017-01-27 18:56 UTC

This package is not auto-updated.

Last update: 2024-09-23 15:10:27 UTC


README

将函数/闭包推送到数据库队列。

这是一个真正的队列驱动程序,类似于beanstalkd或redis。您需要一个守护进程,如supervisor或类似进程来监听您的队列。

安装

将此包添加到composer.json的require部分,并运行composer update

"diegowazevedo/laravel-database-queue": ">0.5"

将服务提供者添加到config/app.php中的providers数组

'DWA\Queue\DatabaseServiceProvider'

建议发布迁移,以便它们被复制到您的常规迁移

$ php artisan migrate:publish diegowazevedo/laravel-database-queue

然后运行迁移

$ php artisan migrate 

建议创建failed_jobs表,此刻使用以下命令

$ php artisan queue:failed-table

现在您应该能够在config/queue.php中使用数据库驱动程序

'default' => 'database',

'connections' => array(
    ...
    'database' => array(
        'driver' => 'database',
        'queue' => 'queue-name', // optional, can be null or any string
        'lock_type' => 0, // optional, can be 0, 1 or 2
    ),
    ...
}

它的工作方式与beanstalkd或redis队列监听器相同。

监听新任务

$ php artisan queue:listen

并发性通过queues表中的status列来管理,因此您可以将queue:listen并行化。

状态变更的原子性由数据库事务保证,如果您遇到竞态条件问题,可以将选项lock_type设置为

  • 'lock_type' => 1 // 队列系统将使用sharedLock
  • 'lock_type' => 2 // 队列系统将使用lockForUpdate

更多信息请参见https://laravel.net.cn/docs/4.2/queries#pessimistic-locking

Laravel 队列系统

更多详细信息请参见https://laravel.net.cn/docs/queues

谢谢

基于https://github.com/barryvdh/laravel-async-queue进行修改