Skip to content

Connection from task is not properly used when handling incoming task #131

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

Merged
merged 1 commit into from
Feb 7, 2024
Merged
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
6 changes: 1 addition & 5 deletions src/TaskHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
use Illuminate\Support\Str;
use Illuminate\Validation\ValidationException;
use Safe\Exceptions\JsonException;
use stdClass;
use UnexpectedValueException;
use function Safe\json_decode;

Expand Down Expand Up @@ -98,11 +97,8 @@ private function captureTask($task): array

private function loadQueueConnectionConfiguration(array $task): void
{
/**
* @var stdClass $command
*/
$command = self::getCommandProperties($task['data']['command']);
$connection = $command->connection ?? config('queue.default');
$connection = $command['connection'] ?? config('queue.default');
$baseConfig = config('queue.connections.' . $connection);
$config = (new CloudTasksConnector())->connect($baseConfig)->config;

Expand Down
20 changes: 20 additions & 0 deletions tests/TaskHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,26 @@ public function it_can_run_a_task()
Log::assertLogged('SimpleJob:success');
}

/**
* @test
*/
public function it_can_run_a_task_using_the_task_connection()
{
// Arrange
OpenIdVerificator::fake();
Log::swap(new LogFake());
Event::fake([JobProcessing::class, JobProcessed::class]);
$this->app['config']->set('queue.default', 'non-existing-connection');

// Act
$job = new SimpleJob();
$job->connection = 'my-cloudtasks-connection';
$this->dispatch($job)->runWithoutExceptionHandler();

// Assert
Log::assertLogged('SimpleJob:success');
}

/**
* @test
*/
Expand Down