-
-
Notifications
You must be signed in to change notification settings - Fork 39
Explicitly specify job queue #147
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
|
||
use Google\Cloud\Tasks\V2\HttpMethod; | ||
use Google\Cloud\Tasks\V2\Task; | ||
use Illuminate\Queue\CallQueuedClosure; | ||
use Illuminate\Queue\Events\JobProcessed; | ||
use Illuminate\Queue\Events\JobProcessing; | ||
use Illuminate\Queue\Events\JobQueued; | ||
|
@@ -146,17 +147,22 @@ public function it_posts_the_task_the_correct_queue() | |
// Arrange | ||
CloudTasksApi::fake(); | ||
|
||
$closure = fn () => 'closure job'; | ||
$closureDisplayName = CallQueuedClosure::create($closure)->displayName(); | ||
|
||
// Act | ||
$this->dispatch((new SimpleJob())); | ||
$this->dispatch((new FailingJob())->onQueue('my-special-queue')); | ||
$this->dispatch($closure); | ||
$this->dispatch($closure, 'my-special-queue'); | ||
|
||
// Assert | ||
CloudTasksApi::assertTaskCreated(function (Task $task, string $queueName): bool { | ||
$decoded = json_decode($task->getHttpRequest()->getBody(), true); | ||
$command = IncomingTask::fromJson($task->getHttpRequest()->getBody())->command(); | ||
|
||
return $decoded['displayName'] === SimpleJob::class | ||
&& ($command['queue'] ?? null) === null | ||
&& $command['queue'] === 'barbequeue' | ||
Comment on lines
-159
to
+165
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This failed initially after the changes, because |
||
&& $queueName === 'projects/my-test-project/locations/europe-west6/queues/barbequeue'; | ||
}); | ||
|
||
|
@@ -168,6 +174,24 @@ public function it_posts_the_task_the_correct_queue() | |
&& $command['queue'] === 'my-special-queue' | ||
&& $queueName === 'projects/my-test-project/locations/europe-west6/queues/my-special-queue'; | ||
}); | ||
|
||
CloudTasksApi::assertTaskCreated(function (Task $task, string $queueName) use ($closureDisplayName): bool { | ||
$decoded = json_decode($task->getHttpRequest()->getBody(), true); | ||
$command = IncomingTask::fromJson($task->getHttpRequest()->getBody())->command(); | ||
|
||
return $decoded['displayName'] === $closureDisplayName | ||
&& $command['queue'] === 'barbequeue' | ||
&& $queueName === 'projects/my-test-project/locations/europe-west6/queues/barbequeue'; | ||
}); | ||
|
||
CloudTasksApi::assertTaskCreated(function (Task $task, string $queueName) use ($closureDisplayName): bool { | ||
$decoded = json_decode($task->getHttpRequest()->getBody(), true); | ||
$command = IncomingTask::fromJson($task->getHttpRequest()->getBody())->command(); | ||
|
||
return $decoded['displayName'] === $closureDisplayName | ||
&& $command['queue'] === 'my-special-queue' | ||
&& $queueName === 'projects/my-test-project/locations/europe-west6/queues/my-special-queue'; | ||
}); | ||
} | ||
|
||
#[Test] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,13 +33,13 @@ protected function setUp(): void | |
CloudTasksApi::fake(); | ||
} | ||
|
||
#[Override] | ||
protected function tearDown(): void | ||
{ | ||
parent::tearDown(); | ||
#[Override] | ||
protected function tearDown(): void | ||
{ | ||
parent::tearDown(); | ||
|
||
CloudTasksQueue::forgetWorkerOptionsCallback(); | ||
} | ||
CloudTasksQueue::forgetWorkerOptionsCallback(); | ||
} | ||
Comment on lines
-36
to
+42
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I ran |
||
|
||
#[Test] | ||
public function it_can_run_a_task() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,8 @@ | |
namespace Tests; | ||
|
||
use Google\Cloud\Tasks\V2\Client\CloudTasksClient; | ||
use Illuminate\Foundation\Bus\PendingClosureDispatch; | ||
use Illuminate\Foundation\Bus\PendingDispatch; | ||
use Illuminate\Foundation\Testing\DatabaseTransactions; | ||
use Illuminate\Support\Facades\Event; | ||
use Stackkit\LaravelGoogleCloudTasksQueue\CloudTasksServiceProvider; | ||
|
@@ -82,7 +84,7 @@ protected function setConfigValue($key, $value) | |
$this->app['config']->set('queue.connections.my-cloudtasks-connection.'.$key, $value); | ||
} | ||
|
||
public function dispatch($job): DispatchedJob | ||
public function dispatch($job, ?string $onQueue = null): DispatchedJob | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added an optional parameter that allows to set queue for a closure job. |
||
{ | ||
$payload = null; | ||
$task = null; | ||
|
@@ -93,7 +95,11 @@ public function dispatch($job): DispatchedJob | |
$task = $event->task; | ||
}); | ||
|
||
dispatch($job); | ||
tap(dispatch($job), function (PendingClosureDispatch|PendingDispatch $pendingDispatch) use ($onQueue) { | ||
if ($onQueue !== null) { | ||
$pendingDispatch->onQueue($onQueue); | ||
} | ||
}); | ||
|
||
return new DispatchedJob($payload, $task, $this); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Display name of a closure job looks like
Closure (QueueTest.php:150)
. Added this line to keep the ability to assertdisplayName
inCloudTasksApi::assertTaskCreated()
.