rarg27 / laravel-google-cloud-tasks-queue
Requires
- ext-json: *
- firebase/php-jwt: ^5.0
- google/cloud-tasks: ^1.10
- phpseclib/phpseclib: ~2.0
- thecodingmachine/safe: ^1.0|^2.0
Requires (Dev)
- laravel/legacy-factories: ^1.3
- nunomaduro/larastan: ^1.0 || ^2.0
- orchestra/testbench: ^4.0 || ^5.0 || ^6.0 || ^7.0
- thecodingmachine/phpstan-safe-rule: ^1.2
- dev-master
- 3.x-dev
- v3.1.2
- v3.1.1
- v3.1.0
- v3.0.0
- v3.0.0-beta3
- v3.0.0-beta2
- v3.0.0-beta1
- 2.x-dev
- v2.3.0
- v2.2.1
- v2.2.0
- v2.2.0-beta1
- v2.1.3
- v2.1.2
- v2.1.1
- v2.1.0
- v2.1.0-beta1
- v2.0.1
- v2.0.0
- 1.x-dev
- v1.0.0
- v1.0.0-alpha1
- dev-bugfix/openid-audience
- dev-feature/dispatch-deadline
- dev-dependabot/npm_and_yarn/dashboard/minimist-1.2.6
- dev-development
This package is not auto-updated.
Last update: 2024-11-10 15:18:33 UTC
README
Introduction
This package allows Google Cloud Tasks to be used as the queue driver.
Requirements
This package requires Laravel 6 or higher and supports MySQL 8 and PostgreSQL 14. Might support older database versions too, but package hasn't been tested for it.
Please check the table below for supported Laravel and PHP versions:
Installation
Require the package using Composer
composer require stackkit/laravel-google-cloud-tasks-queue
Add a new queue connection to config/queue.php
'cloudtasks' => [ 'driver' => 'cloudtasks', 'project' => env('STACKKIT_CLOUD_TASKS_PROJECT', ''), 'location' => env('STACKKIT_CLOUD_TASKS_LOCATION', ''), 'handler' => env('STACKKIT_CLOUD_TASKS_HANDLER', ''), 'queue' => env('STACKKIT_CLOUD_TASKS_QUEUE', 'default'), 'service_account_email' => env('STACKKIT_CLOUD_TASKS_SERVICE_EMAIL', ''), // Optional: The deadline in seconds for requests sent to the worker. If the worker // does not respond by this deadline then the request is cancelled and the attempt // is marked as a DEADLINE_EXCEEDED failure. 'dispatch_deadline' => null, ],
Update the QUEUE_CONNECTION
environment variable
QUEUE_CONNECTION=cloudtasks
Now that the package is installed, the final step is to set the correct environment variables.
Please check the table below on what the values mean and what their value should be.
How it works
Using Cloud Tasks as a Laravel queue driver is fundamentally different than other Laravel queue drivers, like Redis.
Typically a Laravel queue has a worker that listens to incoming jobs using the queue:work
/ queue:listen
command.
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.
Dashboard (beta)
The package comes with a beautiful dashboard that can be used to monitor all queued jobs.
Experimental
The dashboard works by storing all outgoing tasks in a database table. When Cloud Tasks calls the application and this package handles the task, we will automatically update the tasks' status, attempts and possible errors.
There is probably a (small) performance penalty because each task dispatch and handling does extra database read and writes. Also, the dashboard has not been tested with high throughput queues.
To make use of it, enable it through the .env
file:
STACKKIT_CLOUD_TASKS_DASHBOARD_ENABLED=true STACKKIT_CLOUD_TASKS_DASHBOARD_PASSWORD=MySecretLoginPasswordPleaseChangeThis
Then publish its assets and migrations:
php artisan vendor:publish --tag=cloud-tasks php artisan migrate
The dashboard is accessible at the URI: /cloud-tasks
Authentication
Set the GOOGLE_APPLICATION_CREDENTIALS
environment variable with a path to the credentials file.
More info: https://cloud.google.com/docs/authentication/production
If you're not using your master service account (which has all abilities), you must add the following roles to make it works:
- App Engine Viewer
- Cloud Tasks Enqueuer
- Cloud Tasks Viewer
- Cloud Tasks Task Deleter
- Service Account User
Security
The job handler requires each request to have an OpenID token. In the installation step we set the service account email, and with that service account, Cloud Tasks will generate an OpenID token and send it along with the job payload to the handler.
This package verifies that the token is digitally signed by Google. Only Google Tasks will be able to call your handler.
More information about OpenID Connect:
https://developers.google.com/identity/protocols/oauth2/openid-connect
Upgrading
Read [UPGRADING.MD](UPGRADING.md) on how to update versions.