Skip to content

Commit 454a592

Browse files
committed
Move setting maxAttempt to when task is handled
1 parent c0bfc89 commit 454a592

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

src/CloudTasksQueue.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,6 @@ protected function pushToCloudTasks($queue, $payload, $delay = 0, $attempts = 0)
6060
$httpRequest->setHttpMethod(HttpMethod::POST);
6161
$httpRequest->setBody($payload);
6262

63-
$httpRequest->setHeaders([
64-
'X-Stackkit-Max-Attempts' => $this->getMaxAttempts($queueName),
65-
]);
66-
6763
$task = $this->createTask();
6864
$task->setHttpRequest($httpRequest);
6965

@@ -103,9 +99,4 @@ private function createTask()
10399
{
104100
return app(Task::class);
105101
}
106-
107-
private function getMaxAttempts($queue)
108-
{
109-
return $this->client->getQueue($queue)->getRetryConfig()->getMaxAttempts();
110-
}
111102
}

src/TaskHandler.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,13 +121,27 @@ private function handleTask($task)
121121

122122
$job->setAttempts(request()->header('X-CloudTasks-TaskRetryCount') + 1);
123123
$job->setQueue(request()->header('X-Cloudtasks-Queuename'));
124-
$job->setMaxTries(request()->header('X-Stackkit-Max-Attempts'));
124+
$job->setMaxTries($this->getQueueMaxTries($job));
125125

126126
$worker = $this->getQueueWorker();
127127

128128
$worker->process('cloudtasks', $job, new WorkerOptions());
129129
}
130130

131+
private function getQueueMaxTries(CloudTasksJob $job)
132+
{
133+
$queueName = $this->client->queueName(
134+
Config::project(),
135+
Config::location(),
136+
$job->getQueue()
137+
);
138+
139+
return $this->client
140+
->getQueue($queueName)
141+
->getRetryConfig()
142+
->getMaxAttempts();
143+
}
144+
131145
/**
132146
* @return Worker
133147
*/

0 commit comments

Comments
 (0)