Skip to content

Commit 52452fc

Browse files
Merge pull request #144 from stackkit/4.x-dev
Fix short task name passed instead of fully qualified
2 parents d1ea63c + 1d65da7 commit 52452fc

File tree

4 files changed

+17
-4
lines changed

4 files changed

+17
-4
lines changed

src/IncomingTask.php

+14-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace Stackkit\LaravelGoogleCloudTasksQueue;
66

77
use Error;
8+
use Google\Cloud\Tasks\V2\Client\CloudTasksClient;
89
use Illuminate\Contracts\Encryption\Encrypter;
910
use Safe\Exceptions\JsonException;
1011

@@ -51,13 +52,25 @@ public function queue(): string
5152
return config('queue.connections.'.$this->connection().'.queue');
5253
}
5354

54-
public function taskName(): string
55+
public function shortTaskName(): string
5556
{
5657
return request()->header('X-CloudTasks-TaskName')
5758
?? request()->header('X-AppEngine-TaskName')
5859
?? throw new Error('Unable to extract taskname from header');
5960
}
6061

62+
public function fullyQualifiedTaskName(): string
63+
{
64+
$config = config('queue.connections.'.$this->connection());
65+
66+
return CloudTasksClient::taskName(
67+
project: $config['project'],
68+
location: $config['location'],
69+
queue: $this->queue(),
70+
task: $this->shortTaskName(),
71+
);
72+
}
73+
6174
public function command(): array
6275
{
6376
$command = $this->task['data']['command'];

src/TaskHandler.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function handle(?string $task = null): void
2828
abort(422, 'Invalid task payload');
2929
}
3030

31-
if (! CloudTasksApi::exists($task->taskName())) {
31+
if (! CloudTasksApi::exists($task->fullyQualifiedTaskName())) {
3232
abort(404);
3333
}
3434

tests/IncomingTaskTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function it_reads_the_incoming_task(string $job, string $taskType)
4141

4242
// Assert
4343
Event::assertDispatched(function (TaskIncoming $event) use ($job) {
44-
return $event->task->taskName() === 'projects/my-test-project/locations/europe-west6/queues/barbequeue/tasks/01HSR4V9QE2F4T0K8RBAYQ88KE-'.class_basename($job)
44+
return $event->task->fullyQualifiedTaskName() === 'projects/my-test-project/locations/europe-west6/queues/barbequeue/tasks/01HSR4V9QE2F4T0K8RBAYQ88KE-'.class_basename($job)
4545
&& $event->task->connection() === 'my-cloudtasks-connection'
4646
&& $event->task->queue() === 'barbequeue';
4747
});

tests/Support/DispatchedJob.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function run(): void
3535
method: 'POST',
3636
uri: route('cloud-tasks.handle-task'),
3737
server: [
38-
$header => $this->task->getName(),
38+
$header => (string) str($this->task->getName())->after('/tasks/'),
3939
],
4040
content: $this->payload,
4141
);

0 commit comments

Comments
 (0)