Skip to content

Commit

Permalink
Merge pull request #1851 from denissonleal/hotfix/multiconnection-queue
Browse files Browse the repository at this point in the history
fix queued mongodb usage check
  • Loading branch information
jenssegers authored Oct 18, 2019
2 parents 4c75151 + e8b6e75 commit cdc6e1d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/Jenssegers/Mongodb/MongodbQueueServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Jenssegers\Mongodb;

use DB;
use Illuminate\Queue\QueueServiceProvider;
use Jenssegers\Mongodb\Queue\Failed\MongoFailedJobProvider;

Expand All @@ -13,7 +14,7 @@ class MongodbQueueServiceProvider extends QueueServiceProvider
protected function registerFailedJobServices()
{
// Add compatible queue failer if mongodb is configured.
if (config('queue.failed.database') == 'mongodb') {
if (DB::connection(config('queue.failed.database'))->getDriverName() == 'mongodb') {
$this->app->singleton('queue.failer', function ($app) {
return new MongoFailedJobProvider($app['db'], config('queue.failed.database'), config('queue.failed.table'));
});
Expand Down
9 changes: 9 additions & 0 deletions tests/QueueTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php
declare(strict_types=1);

use Jenssegers\Mongodb\Queue\Failed\MongoFailedJobProvider;

class QueueTest extends TestCase
{
public function setUp(): void
Expand Down Expand Up @@ -56,6 +58,13 @@ public function testQueueJobExpired(): void
$this->assertEquals(0, Queue::getDatabase()->table(Config::get('queue.connections.database.table'))->count());
}

public function testFailQueueJob(): void
{
$provider = app('queue.failer');

$this->assertInstanceOf(MongoFailedJobProvider::class, $provider);
}

public function testFindFailJobNull(): void
{
Config::set('queue.failed.database', 'mongodb');
Expand Down
3 changes: 3 additions & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ protected function getPackageProviders($app)
{
return [
Jenssegers\Mongodb\MongodbServiceProvider::class,
Jenssegers\Mongodb\MongodbQueueServiceProvider::class,
Jenssegers\Mongodb\Auth\PasswordResetServiceProvider::class,
Jenssegers\Mongodb\Validation\ValidationServiceProvider::class,
];
Expand All @@ -50,6 +51,7 @@ protected function getEnvironmentSetUp($app)
$app['config']->set('database.default', 'mongodb');
$app['config']->set('database.connections.mysql', $config['connections']['mysql']);
$app['config']->set('database.connections.mongodb', $config['connections']['mongodb']);
$app['config']->set('database.connections.mongodb2', $config['connections']['mongodb']);
$app['config']->set('database.connections.dsn_mongodb', $config['connections']['dsn_mongodb']);

$app['config']->set('auth.model', 'User');
Expand All @@ -63,5 +65,6 @@ protected function getEnvironmentSetUp($app)
'queue' => 'default',
'expire' => 60,
]);
$app['config']->set('queue.failed.database', 'mongodb2');
}
}

0 comments on commit cdc6e1d

Please sign in to comment.