Laravel Google Cloud Tasks Queue package allows Google Cloud Tasks to be used as the queue driver. This package requires Laravel 6 or higher and supports MySQL 8 and PostgreSQL 14. Might support older database versions too, but the package hasn't been tested for it.
For the installation purpose, Please require the package using Composer.
composer require stackkit/laravel-google-cloud-tasks-queue
Add a new queue connection to
'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 canceled and the attempt // is marked as a DEADLINE_EXCEEDED failure. 'dispatch_deadline' => null, 'backoff' => 0, ],
QUEUE_CONNECTION environment variable
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: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
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 reads and writes. Also, the dashboard has not been tested with high throughput queues.
To make use of it, enable it through the
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
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:
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.
For more details about this package, Please visit Github.
Published at : 17-11-2022
I am a highly results-driven professional with 12+ years of collective experience in the grounds of web application development especially in laravel, native android application development in java, and desktop application development in the dot net framework. Now managing a team of expert developers at Codebrisk.