|
| 1 | +# Introduction |
| 2 | + |
| 3 | +This package allows you to use Google Cloud Tasks as your queue driver. |
| 4 | + |
| 5 | +# How it works [!] |
| 6 | + |
| 7 | +!! Please read this next section !! |
| 8 | + |
| 9 | +You may already know this, but using Google Cloud Tasks is fundamentally different than typical Laravel queues. |
| 10 | + |
| 11 | +Typically a Laravel queue has a worker that listens to incoming jobs using the `queue:work` / `queue:listen` command. |
| 12 | +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. |
| 13 | + |
| 14 | +Please read the following resource on how to correctly configure your queue so your application doesn't get overloaded with queue request: |
| 15 | + |
| 16 | +https://cloud.google.com/tasks/docs/configuring-queues |
| 17 | + |
| 18 | +This package uses the HTTP request handler and doesnt' support AppEngine yet. But feel free to contribute! I myself don't use AppEngine. |
| 19 | + |
| 20 | +# Installation |
| 21 | + |
| 22 | +(1) Require the package using Composer |
| 23 | + |
| 24 | +```bash |
| 25 | +composer require stackkit/laravel-google-cloud-tasks-queue |
| 26 | +``` |
| 27 | + |
| 28 | +(2) Create a new Cloud Tasks queue using `gcloud` |
| 29 | + |
| 30 | +````bash |
| 31 | +gcloud tasks queues create [QUEUE_ID] |
| 32 | +```` |
| 33 | + |
| 34 | +[Official documentation - Creating Cloud Tasks queues](https://cloud.google.com/tasks/docs/creating-queues) |
| 35 | + |
| 36 | +(3) Add a new queue connection to `config/queue.php` |
| 37 | + |
| 38 | +``` |
| 39 | +'cloudtasks' => [ |
| 40 | + 'driver' => 'cloudtasks', |
| 41 | + 'credentials' => base_path('gcloud-key.json'), |
| 42 | + 'project' => env('STACKKIT_CLOUD_TASKS_PROJECT', ''), |
| 43 | + 'location' => env('STACKKIT_CLOUD_TASKS_LOCATION', ''), |
| 44 | + 'handler' => env('STACKKIT_CLOUD_TASKS_HANDLER', ''), |
| 45 | + 'queue' => env('STACKKIT_CLOUD_TASKS_QUEUE', 'default'), |
| 46 | +], |
| 47 | +``` |
| 48 | + |
| 49 | +(4) Update the `QUEUE_CONNECTION` environment variable |
| 50 | + |
| 51 | +``` |
| 52 | +QUEUE_CONNECTION=cloudtasks |
| 53 | +``` |
0 commit comments