Skip to content

Commit 1090e10

Browse files
committed
Updated README.md
1 parent 9636876 commit 1090e10

File tree

1 file changed

+81
-17
lines changed

1 file changed

+81
-17
lines changed

README.md

Lines changed: 81 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,16 @@
1111

1212
This package allows you to use Google Cloud Tasks as your queue driver.
1313

14-
**This is a WIP package, use at own risk**
14+
# How it works
1515

16-
# How it works [!]
17-
18-
!! Please read this next section !!
19-
20-
You may already know this, but using Google Cloud Tasks is fundamentally different than typical Laravel queues.
16+
Using Cloud Tasks as a Laravel queue driver is fundamentally different than other Laravel queue drivers, like Redis.
2117

2218
Typically a Laravel queue has a worker that listens to incoming jobs using the `queue:work` / `queue:listen` command.
2319
With Cloud Tasks, this is not the case. Instead, Cloud Tasks will schedule the job for you and make an HTTP request to your application with the job payload. There is no need to run a `queue:work/listen` command.
2420

25-
Please read the following resource on how to correctly configure your queue so your application doesn't get overloaded with queue request:
26-
27-
https://cloud.google.com/tasks/docs/configuring-queues
21+
For more information on how to configure the Cloud Tasks queue, read the next section [Configuring the queue](#configuring-the-queue)
2822

29-
This package uses the HTTP request handler and doesnt' support AppEngine yet. But feel free to contribute! I myself don't use AppEngine.
23+
This package uses the HTTP request handler and doesn't support AppEngine. But feel free to contribute!
3024

3125
# Requirements
3226

@@ -50,15 +44,10 @@ Please check the table below for supported Laravel and PHP versions:
5044
composer require stackkit/laravel-google-cloud-tasks-queue
5145
```
5246

53-
(2) Create a new Cloud Tasks queue using `gcloud`
54-
55-
````bash
56-
gcloud tasks queues create [QUEUE_ID]
57-
````
5847

5948
[Official documentation - Creating Cloud Tasks queues](https://cloud.google.com/tasks/docs/creating-queues)
6049

61-
(3) Add a new queue connection to `config/queue.php`
50+
(2) Add a new queue connection to `config/queue.php`
6251

6352
```
6453
'cloudtasks' => [
@@ -72,8 +61,83 @@ gcloud tasks queues create [QUEUE_ID]
7261
],
7362
```
7463

75-
(4) Update the `QUEUE_CONNECTION` environment variable
64+
(3) Update the `QUEUE_CONNECTION` environment variable
7665

7766
```
7867
QUEUE_CONNECTION=cloudtasks
7968
```
69+
70+
(4) Create a new Cloud Tasks queue using `gcloud`
71+
72+
````bash
73+
gcloud tasks queues create [QUEUE_ID]
74+
````
75+
76+
Now that the package is installed, the final step is to set the correct environment variables.
77+
78+
Please check the table below on what the values mean and what their value should be.
79+
80+
|Environment variable|Description|Example
81+
|---|---|---
82+
|`STACKKIT_CLOUD_TASKS_PROJECT`|The project your queue belongs to.|`my-project`
83+
|`STACKKIT_CLOUD_TASKS_LOCATION`|The region where the AppEngine is hosted|`europe-west6`
84+
|`STACKKIT_CLOUD_TASKS_HANDLER`|The URL that Cloud Tasks will call to process a job. This should be the URL to your Laravel app with the `handle-task` path added|`https://<your website>.com/handle-task`
85+
|`STACKKIT_CLOUD_TASKS_QUEUE`|The queue a job will be added to|`emails`
86+
|`STACKKIT_CLOUD_TASKS_SERVICE_EMAIL`|The emailaddress of the AppEngine service account. Important, it should have the *Cloud Tasks Enqueuer* role|`[email protected]`
87+
# Configuring the queue
88+
89+
When you first create a queue using `gcloud tasks queues create`, the default settings will look something like this:
90+
91+
```
92+
rateLimits:
93+
maxBurstSize: 100
94+
maxConcurrentDispatches: 1000
95+
maxDispatchesPerSecond: 500.0
96+
retryConfig:
97+
maxAttempts: 100
98+
maxBackoff: 3600s
99+
maxDoublings: 16
100+
minBackoff: 0.100s
101+
```
102+
103+
## Configurable settings
104+
105+
### maxBurstSize
106+
107+
Max burst size limits how fast tasks in queue are processed when many tasks are in the queue and the rate is high.
108+
109+
### maxConcurrentDispatches
110+
111+
The maximum number of concurrent tasks that Cloud Tasks allows to be dispatched for this queue
112+
113+
### maxDispatchesPerSecond
114+
115+
The maximum rate at which tasks are dispatched from this queue.
116+
117+
### maxAttempts
118+
119+
Number of attempts per task. Cloud Tasks will attempt the task max_attempts times (that is, if the first attempt fails, then there will be max_attempts - 1 retries). Must be >= -1.|
120+
121+
### maxBackoff
122+
123+
A task will be scheduled for retry between min_backoff and max_backoff duration after it fails
124+
125+
### maxDoublings
126+
127+
The time between retries will double max_doublings times.
128+
129+
A task's retry interval starts at min_backoff, then doubles max_doublings times, then increases linearly, and finally retries retries at intervals of max_backoff up to max_attempts times.
130+
131+
For example, if min_backoff is 10s, max_backoff is 300s, and max_doublings is 3, then the a task will first be retried in 10s. The retry interval will double three times, and then increase linearly by 2^3 * 10s. Finally, the task will retry at intervals of max_backoff until the task has been attempted max_attempts times. Thus, the requests will retry at 10s, 20s, 40s, 80s, 160s, 240s, 300s, 300s, ....
132+
133+
## Recommended settings for Laravel
134+
135+
To simulate a single `queue:work/queue:listen` process, simply set the `maxConcurrentDispatches` to 1:
136+
137+
```
138+
gcloud tasks queues update [QUEUE_ID] --max-concurrent-dispatches=1
139+
```
140+
141+
More information on configuring queues:
142+
143+
https://cloud.google.com/tasks/docs/configuring-queues

0 commit comments

Comments
 (0)