Skip to content

Manage specific connection in config #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions config/one-time-operations.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,8 @@
// Database Connection Name - Change the model connection, support for Multitenancy
// Only change when you want to deviate from your system default repository
'connection' => null,

// Queue Connection Name
// Only change when you want to use a specific queue connection different from default
'queue_connection' => env('ONE_TIME_OPERATIONS_QUEUE_CONNECTION', env('QUEUE_CONNECTION', 'sync')),
];
1 change: 1 addition & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@
</coverage>
<php>
<env name="DB_CONNECTION" value="testing"/>
<env name="QUEUE_CONNECTION" value="default"/>
</php>
</phpunit>
4 changes: 3 additions & 1 deletion src/Commands/OneTimeOperationsProcessCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,9 @@ protected function storeOperation(OneTimeOperationFile $operationFile): void
protected function dispatchOperationJob(OneTimeOperationFile $operationFile)
{
if ($this->isAsyncMode($operationFile)) {
OneTimeOperationProcessJob::dispatch($operationFile->getOperationName())->onQueue($this->getQueue($operationFile));
OneTimeOperationProcessJob::dispatch($operationFile->getOperationName())
->onQueue($this->getQueue($operationFile))
->onConnection(OneTimeOperationManager::getConnectionName());

return;
}
Expand Down
5 changes: 5 additions & 0 deletions src/OneTimeOperationManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ public static function getDirectoryName(): string
return Config::get('one-time-operations.directory');
}

public static function getConnectionName(): string
{
return Config::get('one-time-operations.queue_connection');
}

public static function getDirectoryPath(): string
{
return App::basePath(Str::of(self::getDirectoryName())->rtrim('/')).DIRECTORY_SEPARATOR;
Expand Down
4 changes: 4 additions & 0 deletions tests/Feature/OneTimeOperationCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace TimoKoerber\LaravelOneTimeOperations\Tests\Feature;

use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Queue;
use Orchestra\Testbench\TestCase;
Expand All @@ -24,6 +25,9 @@ protected function setUp(): void

Queue::fake();
Carbon::setTestNow(self::TEST_DATETIME);

Config::set('queue.default', 'default');

}

protected function getPackageProviders($app): array
Expand Down
11 changes: 6 additions & 5 deletions tests/Feature/OneTimeOperationCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace TimoKoerber\LaravelOneTimeOperations\Tests\Feature;

use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Queue;
use Illuminate\Support\Str;
Expand Down Expand Up @@ -113,7 +114,7 @@ public function test_the_whole_command_process()
// operation was exectued - database entry and job was created
$this->assertEquals(1, Operation::count());
Queue::assertPushed(OneTimeOperationProcessJob::class, function (OneTimeOperationProcessJob $job) {
return $job->connection === null; // async
return $job->connection === Config::get('one-time-operations.queue_connection'); // async
});

// entry was created successfully
Expand Down Expand Up @@ -221,7 +222,7 @@ public function test_sync_processing_with_file_attribute()
// Job was executed asynchronously
Queue::assertPushed(OneTimeOperationProcessJob::class, function (OneTimeOperationProcessJob $job) {
return $job->operationName === '2015_10_21_072800_foo_bar_operation'
&& $job->connection === null // async
&& $job->connection === Config::get('one-time-operations.queue_connection') // async
&& $job->queue === 'default'; // default queue
});

Expand All @@ -237,7 +238,7 @@ public function test_sync_processing_with_file_attribute()
// Job was executed asynchronously on queue "foobar"
Queue::assertPushed(OneTimeOperationProcessJob::class, function (OneTimeOperationProcessJob $job) {
return $job->operationName === '2015_10_21_072800_foo_bar_operation'
&& $job->connection === null // async
&& $job->connection === Config::get('one-time-operations.queue_connection') // async
&& $job->queue === 'foobar'; // default queue
});
}
Expand All @@ -258,7 +259,7 @@ public function test_processing_with_queue()
// Job was executed synchronously
Queue::assertPushed(OneTimeOperationProcessJob::class, function (OneTimeOperationProcessJob $job) {
return $job->operationName === '2015_10_21_072800_foo_bar_operation'
&& $job->connection === null // async
&& $job->connection === Config::get('one-time-operations.queue_connection') // async
&& $job->queue === 'narfpuit'; // queue narfpuit
});

Expand All @@ -270,7 +271,7 @@ public function test_processing_with_queue()
// Job was executed asynchronously on queue "foobar"
Queue::assertPushed(OneTimeOperationProcessJob::class, function (OneTimeOperationProcessJob $job) {
return $job->operationName === '2015_10_21_072800_foo_bar_operation'
&& $job->connection === null // async
&& $job->connection === Config::get('one-time-operations.queue_connection') // async
&& $job->queue === 'foobar'; // queue foobar
});
}
Expand Down