Skip to content

Commit 78011f5

Browse files
committed
feat: manage specific queue connection in config
1 parent df0cc43 commit 78011f5

File tree

6 files changed

+23
-6
lines changed

6 files changed

+23
-6
lines changed

config/one-time-operations.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,8 @@
1111
// Database Connection Name - Change the model connection, support for Multitenancy
1212
// Only change when you want to deviate from your system default repository
1313
'connection' => null,
14+
15+
// Queue Connection Name
16+
// Only change when you want to use a specific queue connection different from default
17+
'queue_connection' => env('ONE_TIME_OPERATIONS_QUEUE_CONNECTION', env('QUEUE_CONNECTION', 'sync')),
1418
];

phpunit.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,6 @@
1616
</coverage>
1717
<php>
1818
<env name="DB_CONNECTION" value="testing"/>
19+
<env name="QUEUE_CONNECTION" value="default"/>
1920
</php>
2021
</phpunit>

src/Commands/OneTimeOperationsProcessCommand.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,9 @@ protected function storeOperation(OneTimeOperationFile $operationFile): void
161161
protected function dispatchOperationJob(OneTimeOperationFile $operationFile)
162162
{
163163
if ($this->isAsyncMode($operationFile)) {
164-
OneTimeOperationProcessJob::dispatch($operationFile->getOperationName())->onQueue($this->getQueue($operationFile));
164+
OneTimeOperationProcessJob::dispatch($operationFile->getOperationName())
165+
->onQueue($this->getQueue($operationFile))
166+
->onConnection(OneTimeOperationManager::getConnectionName());
165167

166168
return;
167169
}

src/OneTimeOperationManager.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,11 @@ public static function getDirectoryName(): string
108108
return Config::get('one-time-operations.directory');
109109
}
110110

111+
public static function getConnectionName(): string
112+
{
113+
return Config::get('one-time-operations.queue_connection');
114+
}
115+
111116
public static function getDirectoryPath(): string
112117
{
113118
return App::basePath(Str::of(self::getDirectoryName())->rtrim('/')).DIRECTORY_SEPARATOR;

tests/Feature/OneTimeOperationCase.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace TimoKoerber\LaravelOneTimeOperations\Tests\Feature;
44

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

2526
Queue::fake();
2627
Carbon::setTestNow(self::TEST_DATETIME);
28+
29+
Config::set('queue.default', 'default');
30+
2731
}
2832

2933
protected function getPackageProviders($app): array

tests/Feature/OneTimeOperationCommandTest.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace TimoKoerber\LaravelOneTimeOperations\Tests\Feature;
44

55
use Illuminate\Foundation\Testing\RefreshDatabase;
6+
use Illuminate\Support\Facades\Config;
67
use Illuminate\Support\Facades\File;
78
use Illuminate\Support\Facades\Queue;
89
use Illuminate\Support\Str;
@@ -113,7 +114,7 @@ public function test_the_whole_command_process()
113114
// operation was exectued - database entry and job was created
114115
$this->assertEquals(1, Operation::count());
115116
Queue::assertPushed(OneTimeOperationProcessJob::class, function (OneTimeOperationProcessJob $job) {
116-
return $job->connection === null; // async
117+
return $job->connection === Config::get('one-time-operations.queue_connection'); // async
117118
});
118119

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

@@ -237,7 +238,7 @@ public function test_sync_processing_with_file_attribute()
237238
// Job was executed asynchronously on queue "foobar"
238239
Queue::assertPushed(OneTimeOperationProcessJob::class, function (OneTimeOperationProcessJob $job) {
239240
return $job->operationName === '2015_10_21_072800_foo_bar_operation'
240-
&& $job->connection === null // async
241+
&& $job->connection === Config::get('one-time-operations.queue_connection') // async
241242
&& $job->queue === 'foobar'; // default queue
242243
});
243244
}
@@ -258,7 +259,7 @@ public function test_processing_with_queue()
258259
// Job was executed synchronously
259260
Queue::assertPushed(OneTimeOperationProcessJob::class, function (OneTimeOperationProcessJob $job) {
260261
return $job->operationName === '2015_10_21_072800_foo_bar_operation'
261-
&& $job->connection === null // async
262+
&& $job->connection === Config::get('one-time-operations.queue_connection') // async
262263
&& $job->queue === 'narfpuit'; // queue narfpuit
263264
});
264265

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

0 commit comments

Comments
 (0)