-
-
Notifications
You must be signed in to change notification settings - Fork 42
feat: Add Cloud Run Jobs support as queue target #187
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
feat: Add Cloud Run Jobs support as queue target #187
Conversation
Enables dispatching jobs to Cloud Run Jobs instead of HTTP endpoints, allowing for long-running batch processing that exceeds Cloud Tasks HTTP timeout limits. This change introduces a new `cloud_run_job` configuration option for the `cloudtasks` queue connection. When enabled, jobs are dispatched to the Cloud Run Jobs execution API, passing the job payload as environment variables. A new artisan command `cloud-tasks:work-job` is introduced to handle Cloud Run Job executions. Large payloads exceeding environment variable limits can be stored in Laravel filesystem disks, and the path is passed to the Cloud Run Job instead.
- Add cloud-tasks:work-job Artisan command for processing jobs via Cloud Run Jobs - Support Cloud Run Jobs as a target type via Cloud Tasks execution API - Add GCS payload storage for large payloads (>10KB) using Laravel Filesystem - Container overrides pass CLOUD_TASKS_PAYLOAD, CLOUD_TASKS_TASK_NAME, CLOUD_TASKS_PAYLOAD_PATH env vars - Command reads env vars via getenv() and extracts connection from payload - Automatic cleanup of payload files after processing - 23 comprehensive unit tests with 30 assertions
Cloud Run Jobs API requires OAuth authentication with cloud-platform scope. - Changed from OidcToken to OAuthToken - Set scope to 'https://www.googleapis.com/auth/cloud-platform' - Updated test to verify OAuth token configuration
Added comprehensive section covering: - Project-level permissions (cloudtasks.enqueuer, cloudtasks.viewer, run.jobsExecutorWithOverrides, run.invoker) - Service account permissions (iam.serviceAccountUser for SA and Cloud Tasks agent) - Summary table with purpose of each permission
The library only creates/deletes tasks, it does not list queues or tasks. cloudtasks.viewer is only needed if your own application code lists queues/tasks.
|
This is really nice, thanks! I will review everything later. |
Modifies the Cloud Run Job worker to handle job retries by releasing jobs back to Cloud Tasks instead of relying on Cloud Run's retry mechanism. This prevents duplicate job executions when retries are configured on the Cloud Run Job itself, as Laravel manages retries by pushing a new task back to Cloud Tasks when a job is released. This matches the same behaviour as the HTTP request handler Updates tests to reflect the change.
|
|
||
| #### Setup | ||
|
|
||
| 1. **Create a Cloud Run Job** with your Laravel application container, configured to run: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is a little confusing. The command cloud-tasks:work-job doesn't need to be called by the user but it seems like it should. I feel like the setup should start with configuring the queue connection through the config?
| 'queue' => env('CLOUD_TASKS_QUEUE', 'default'), | ||
|
|
||
| // Cloud Run Job configuration | ||
| 'cloud_run_job' => env('CLOUD_TASKS_USE_CLOUD_RUN_JOB', false), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe these options could be added to the main installation config section. But I'm not sure, as it's already quite a big configuration 😅
|
Thanks, it looks really good! I left a few comments. I will go over it again tomorrow or Wednesday just to be sure, and tag it! |
Summary
This PR adds support for processing Laravel queue jobs using Google Cloud Run Jobs as a target type. Instead of dispatching jobs to an HTTP endpoint, Cloud Tasks triggers a Cloud Run Job execution via the Cloud Run Jobs API, which runs an Artisan command to process the job.
Features
Configuration
Breaking Changes
None. This is an additive feature - the cloud_run_job option defaults to false, preserving existing behaviour.
Tests
Documentation