Skip to content

Commit 9b8368c

Browse files
Merge pull request #49 from stackkit/feature/dispatch-deadline
Add support for dispatch deadline
2 parents 6eb9bf9 + 23a1f97 commit 9b8368c

File tree

4 files changed

+34
-0
lines changed

4 files changed

+34
-0
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
55
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
66

7+
## 3.1.0 - 2022-04-09
8+
9+
**Added**
10+
11+
- Added support for `dispatchDeadline`. See README how to configure.
12+
713
## 3.0.0 - 2022-04-03
814

915
**Added**

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ Please check the table below for supported Laravel and PHP versions:
5252
'handler' => env('STACKKIT_CLOUD_TASKS_HANDLER', ''),
5353
'queue' => env('STACKKIT_CLOUD_TASKS_QUEUE', 'default'),
5454
'service_account_email' => env('STACKKIT_CLOUD_TASKS_SERVICE_EMAIL', ''),
55+
// Optional: The deadline for requests sent to the worker. If the worker does not
56+
// respond by this deadline then the request is cancelled and the attempt is
57+
// marked as a DEADLINE_EXCEEDED failure.
58+
'dispatch_deadline' => null,
5559
],
5660
```
5761

src/CloudTasksQueue.php

+5
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Google\Cloud\Tasks\V2\HttpRequest;
88
use Google\Cloud\Tasks\V2\OidcToken;
99
use Google\Cloud\Tasks\V2\Task;
10+
use Google\Protobuf\Duration;
1011
use Google\Protobuf\Timestamp;
1112
use Illuminate\Contracts\Queue\Queue as QueueContract;
1213
use Illuminate\Queue\Queue as LaravelQueue;
@@ -112,6 +113,10 @@ protected function pushToCloudTasks($queue, $payload, $delay = 0)
112113
$task = $this->createTask();
113114
$task->setHttpRequest($httpRequest);
114115

116+
if (!empty($this->config['dispatch_deadline'])) {
117+
$task->setDispatchDeadline(new Duration(['seconds' => $this->config['dispatch_deadline']]));
118+
}
119+
115120
$token = new OidcToken;
116121
$token->setServiceAccountEmail($this->config['service_account_email']);
117122
$httpRequest->setOidcToken($token);

tests/QueueTest.php

+19
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,25 @@ public function it_will_set_the_scheduled_time_when_dispatching_later()
8585
});
8686
}
8787

88+
/**
89+
* @test
90+
*/
91+
public function test_dispatch_deadline_config()
92+
{
93+
// Arrange
94+
CloudTasksApi::fake();
95+
$this->setConfigValue('dispatch_deadline', 30);
96+
97+
// Act
98+
$this->dispatch(new SimpleJob());
99+
100+
// Assert
101+
CloudTasksApi::assertTaskCreated(function (Task $task) {
102+
return $task->hasDispatchDeadline()
103+
&& $task->getDispatchDeadline()->getSeconds() === 30;
104+
});
105+
}
106+
88107
/**
89108
* @test
90109
*/

0 commit comments

Comments
 (0)