firevel/cloud-tasks-queue-driver
Composer 安装命令:
composer require firevel/cloud-tasks-queue-driver
包简介
Cloud Tasks queue driver for Laravel apps running inside Google App Engine.
README 文档
README
A Laravel queue driver for Google Cloud Tasks, enabling serverless job processing for applications running on Google App Engine or Google Cloud Run.
Compatible with both Firevel and standard Laravel applications.
Requirements
- PHP 8.0+ (tested on 8.2, 8.3, and 8.4)
- Laravel 8.x – 12.x (tested against 11.x and 12.x)
- Google Cloud Project with Cloud Tasks API enabled
Installation
composer require firevel/cloud-tasks-queue-driver
The package auto-discovers and registers itself via Laravel's package discovery.
Configuration
Add the connection to your config/queue.php:
'connections' => [ 'cloudtasks' => [ 'driver' => 'cloudtasks', 'project' => env('GOOGLE_CLOUD_PROJECT'), 'location' => env('CLOUD_TASKS_LOCATION', 'us-central1'), 'queue_name' => env('CLOUD_TASKS_QUEUE', 'default'), 'route' => env('CLOUD_TASKS_ROUTE', '/_cloudtasks'), // App Engine specific (optional) 'service' => env('GAE_SERVICE'), 'version' => env('GAE_VERSION'), // Cloud Run specific (optional) 'url' => env('CLOUD_TASKS_URL'), ], ],
Set your default queue connection in .env:
QUEUE_CONNECTION=cloudtasks CLOUD_TASKS_LOCATION=us-central1
Note: The
locationmust match your App Engine or Cloud Run region.
Configuration Options
| Option | Description |
|---|---|
project |
Google Cloud project ID |
location |
Cloud Tasks queue location (must match your compute region) |
queue_name |
Default queue name |
route |
HTTP endpoint path for task callbacks |
service |
App Engine service name (falls back to the GAE_SERVICE env variable when not set) |
version |
App Engine version to route tasks to (when not set, tasks go to the service's default version) |
url |
Custom URL for Cloud Run or when behind a proxy/load balancer |
Cloud Tasks Setup
Create a queue using gcloud:
gcloud tasks queues create default
Or via queue.yaml:
queue: - name: default rate: 500/s
See the Cloud Tasks documentation for advanced queue configuration.
Usage
Use Laravel's standard queue API:
// Dispatch a job dispatch(new ProcessOrder($order)); // Dispatch with delay dispatch(new ProcessOrder($order))->delay(now()->addMinutes(5)); // Dispatch to a specific queue dispatch(new ProcessOrder($order))->onQueue('orders');
Note: Queue names map directly to Cloud Tasks queues, so
onQueue('orders')requires a Cloud Tasks queue namedordersto exist.
How It Works
Unlike traditional queue drivers, there is no queue:work process. Cloud Tasks delivers each job back to your application over HTTP:
- Dispatching a job creates a Cloud Task with the serialized job as its payload, signed with an HMAC-SHA256 signature derived from your
APP_KEY. - Cloud Tasks sends the payload via HTTP POST to the handler route (
/_cloudtasksby default), which the package registers automatically. - The handler verifies the signature, rejects unauthenticated requests with a 403, and processes valid jobs through Laravel's queue worker.
Note: Since job payloads are signed with
APP_KEY, rotating the key will invalidate tasks that were queued before the rotation.
Retries, Attempts and Overlapping
- Retries are managed by the Cloud Tasks queue configuration (
maxAttempts, backoff, etc.). A failed job returns a 500 response and Cloud Tasks redelivers it according to the queue's retry policy. - Per-job attempts are supported: when a job defines
$tries, it is marked as failed once the limit is reached and the handler responds with a 200 so Cloud Tasks stops redelivering it.$job->attempts()is 1-based (1 on the first attempt), derived from theX-CloudTasks-TaskRetryCount/X-AppEngine-TaskRetryCountheaders. - Releasing (
$this->release($delay)) creates a fresh Cloud Task with the same payload, since Cloud Tasks has no native release. The attempt count is carried over in the payload. This also makes theWithoutOverlappingjob middleware work as expected — overlapping jobs are pushed back instead of lost. It requires a cache store that supports atomic locks. - Unique jobs (
ShouldBeUnique) work out of the box; the unique lock is handled by Laravel at dispatch time and also requires a lock-capable cache store. - To process an entire queue serially (one task at a time), set
maxConcurrentDispatches=1on the Cloud Tasks queue — no application code needed.
Routing Behavior
- App Engine: Tasks are routed to the specific service and version that dispatched them, ensuring version consistency during deployments.
- Cloud Run: Tasks are routed to the currently promoted revision.
Testing
The test suite uses Orchestra Testbench and runs without any Google Cloud credentials (the Cloud Tasks client is mocked).
composer install
composer test
Tests run automatically via GitHub Actions on PHP 8.2, 8.3, and 8.4 for every push and pull request.
License
MIT
firevel/cloud-tasks-queue-driver 适用场景与选型建议
firevel/cloud-tasks-queue-driver 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 12.5k 次下载、GitHub Stars 达 4, 最近一次更新时间为 2020 年 10 月 07 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「queue」 「laravel」 「firevel」 「cloud tasks」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 firevel/cloud-tasks-queue-driver 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 firevel/cloud-tasks-queue-driver 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 firevel/cloud-tasks-queue-driver 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Laravel Stackdriver log channel for Google App Engine
Firestore wrapper for Laravel app running inside Google App Engine.
PHP AMQP Binding Library
A Laravel package to monitor queue jobs.
Model random ID generator for Laravel.
Mirror Laravel model inside Firestore collection.
统计信息
- 总下载量: 12.5k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 23
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-10-07