stackkit / laravel-google-cloud-tasks-queue
Google Cloud Tasks queue driver for Laravel
Fund package maintenance!
marickvantuil
Installs: 478 439
Dependents: 0
Suggesters: 0
Security: 0
Stars: 78
Watchers: 2
Forks: 39
Open Issues: 2
pkg:composer/stackkit/laravel-google-cloud-tasks-queue
Requires
- php: ^8.1
- ext-json: *
- google/cloud-tasks: ^2.0
- thecodingmachine/safe: ^3.0
Requires (Dev)
- larastan/larastan: ^3.0
- laravel/pint: ^1.13
- orchestra/testbench: ^10.0
- thecodingmachine/phpstan-safe-rule: ^1.2
- dev-master
- v5.0.2
- v5.0.1
- v5.0.0
- v5.0.0-beta.1
- 4.x-dev
- v4.3.1
- v4.3.0
- v4.2.4-beta.1
- v4.2.3
- v4.2.3-beta.5
- v4.2.3-beta.4
- v4.2.3-beta.3
- v4.2.3-beta.2
- v4.2.3-beta.1
- v4.2.2
- v4.2.1
- v4.2.0
- v4.1.1
- v4.1.0
- v4.0.0
- v4.0.0-beta.2
- v4.0.0-beta.1
- 3.x-dev
- v3.7.0
- v3.7.0-beta.2
- v3.7.0-beta.1
- v3.6.6
- v3.6.5
- v3.6.4
- v3.6.3
- v3.6.2
- v3.6.1
- v3.6.0
- v3.5.2
- v3.5.1
- v3.5.0
- v3.4.1
- v3.4.1-rc1
- v3.4.0
- v3.3.3
- v3.3.2
- v3.3.1
- v3.3.0
- v3.3.0-beta1
- v3.2.1
- v3.2.0
- v3.1.4
- v3.1.3
- 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/laravel-12-failover-queue
This package is auto-updated.
Last update: 2025-10-15 18:37:10 UTC
README
This package allows you to use Google Cloud Tasks as the queue driver in your Laravel application.
Companion packages: Cloud Scheduler, Cloud Logging
Requirements
This package requires Laravel 11 or 12.
Installation
Require the package via Composer:
composer require stackkit/laravel-google-cloud-tasks-queue
Add a new queue connection to config/queue.php:
'cloudtasks' => [ 'driver' => 'cloudtasks', 'project' => env('CLOUD_TASKS_PROJECT', ''), 'location' => env('CLOUD_TASKS_LOCATION', ''), 'queue' => env('CLOUD_TASKS_QUEUE', 'default'), // Required when using App Engine 'app_engine' => env('APP_ENGINE_TASK', false), 'app_engine_service' => env('APP_ENGINE_SERVICE', ''), // Required when not using App Engine 'handler' => env('CLOUD_TASKS_HANDLER', ''), 'service_account_email' => env('CLOUD_TASKS_SERVICE_EMAIL', ''), 'backoff' => 0, 'after_commit' => false, // Enable this if you want to set a non-default Google Cloud Tasks dispatch timeout //'dispatch_deadline' => 1800, // in seconds ],
Set the appropriate environment variables:
QUEUE_CONNECTION=cloudtasks
If you're using Cloud Run:
CLOUD_TASKS_PROJECT=my-project CLOUD_TASKS_LOCATION=europe-west6 CLOUD_TASKS_QUEUE=barbequeue CLOUD_TASKS_SERVICE_EMAIL=my-service-account@appspot.gserviceaccount.com # Optional (when using a separate task handler): CLOUD_TASKS_SERVICE_HANDLER=
If you're using App Engine:
CLOUD_TASKS_PROJECT=my-project CLOUD_TASKS_LOCATION=europe-west6 CLOUD_TASKS_QUEUE=barbequeue APP_ENGINE_TASK=true APP_ENGINE_SERVICE=my-service
Refer to the table below for descriptions of each value:
| Environment Variable | Description | Example |
|---|---|---|
CLOUD_TASKS_PROJECT |
The project your queue belongs to. | my-project |
CLOUD_TASKS_LOCATION |
The region where the project is hosted. | europe-west6 |
CLOUD_TASKS_QUEUE |
The default queue to which a job will be added. | emails |
| App Engine | ||
APP_ENGINE_TASK (optional) |
Set to true to use an App Engine task (otherwise an HTTP task will be used). Defaults to false. | true |
APP_ENGINE_SERVICE (optional) |
The App Engine service that will handle the task (only if using App Engine tasks). | api |
| Non-App Engine Apps | ||
CLOUD_TASKS_SERVICE_EMAIL (optional) |
The service account's email address. It must have the required roles (see below). | my-service-account@appspot.gserviceaccount.com |
CLOUD_TASKS_HANDLER (optional) |
The URL that Cloud Tasks will call to process a job. Should point to your Laravel app. Defaults to the URL that dispatched the job. | https://<your-website>.com |
Optionally, you may publish the config file:
php artisan vendor:publish --tag=cloud-tasks
If you're using separate services for dispatching and handling tasks, and your app should only dispatch jobs (not handle them), you may disable the task handler in config/cloud-tasks.php:
'disable_task_handler' => env('CLOUD_TASKS_DISABLE_TASK_HANDLER', false),
How-To
Pass headers to a task
You can pass headers to a task using the setTaskHeadersUsing method on the CloudTasksQueue class:
use Stackkit\LaravelGoogleCloudTasksQueue\CloudTasksQueue; CloudTasksQueue::setTaskHeadersUsing(static fn() => [ 'X-My-Header' => 'My-Value', ]);
You can also access the payload being dispatched:
CloudTasksQueue::setTaskHeadersUsing(static fn(array $payload) => [ 'X-My-Header' => $payload['displayName'], ]);
Configure the task handler URL
Set the handler URL for a task using the configureHandlerUrlUsing method:
CloudTasksQueue::configureHandlerUrlUsing(static fn() => 'https://example.com/my-url');
Or access the job being dispatched:
CloudTasksQueue::configureHandlerUrlUsing(static fn(MyJob $job) => 'https://example.com/my-url/' . $job->something());
Configure worker options
Customize worker options using the configureWorkerOptionsUsing method:
use Stackkit\LaravelGoogleCloudTasksQueue\IncomingTask; CloudTasksQueue::configureWorkerOptionsUsing(function (IncomingTask $task) { $queueTries = [ 'high' => 5, 'low' => 1, ]; return new WorkerOptions(maxTries: $queueTries[$task->queue()] ?? 1); });
Use a custom credentials file
Edit the client_options key in config/cloud-tasks.php:
'client_options' => [ 'credentials' => '/path/to/credentials.json', ]
Modify CloudTasksClient options
Edit the client_options key in config/cloud-tasks.php:
'client_options' => [ // Custom options here ]
How it works & differences
Using Cloud Tasks as a Laravel queue driver is fundamentally different from other drivers like Redis.
With Redis or similar drivers, a worker listens for jobs via queue:work or queue:listen.
With Cloud Tasks, jobs are scheduled and dispatched via HTTP requests to your app.
There’s no need to run queue:work or queue:listen.
Good to Know
Cloud Tasks has its own retry configuration options like:
- Maximum number of attempts
- Retry duration
- Min/max backoff
- Max doublings
These are ignored by this package. Instead, you can configure retry behavior directly in Laravel.
Authentication
If you're not using your master service account (which has all abilities), assign the following roles to your service account to make it working:
- App Engine Viewer
- Cloud Tasks Enqueuer
- Cloud Tasks Viewer
- Cloud Tasks Task Deleter
- Service Account User
Upgrading
See UPGRADING.MD for instructions on updating versions.
Troubleshooting
HttpRequest.url must start with https://
This can occur when your application runs behind a reverse proxy.
To resolve it, add your app’s domain to Laravel’s trusted proxies.
You may need to use the wildcard *.
Maximum call stack size (zend.max_allowed_stack_size - zend.reserved_stack_size) reached. Infinite recursion?
This seems to be a bug in PHP 8.3 and googleapis/gax-php.
See this issue for details.
A possible workaround is to disable the PHP 8.3 stack limit in php.ini:
zend.max_allowed_stack_size=-1
Contributing
You can use the services defined in docker-compose.yml to run the package locally.
Inside the container:
- Run
composer install - Set up the environment:
cp .env.example .env
Some tests use the Cloud Tasks API and require a project and credentials.
Set the appropriate variables in your .env.