Skip to content

Conversation

@robertpcontreras-ts
Copy link

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

  • New Artisan command: cloud-tasks:work-job - Processes jobs via Cloud Run Jobs container execution
  • Cloud Run Jobs API integration: Cloud Tasks dispatches to run.googleapis.com/v2/.../jobs/{job}:run
  • Environment variable passing: Job payload and task name passed via containerOverrides.env
  • Large payload storage: Payloads exceeding a configurable threshold are stored in Laravel Filesystem (GCS, S3, etc.) and retrieved by the worker
  • OAuth authentication: Uses OAuth token with cloud-platform scope for Cloud Run Jobs API

Configuration

'cloudtasks' => [
    // ... existing config
    'cloud_run_job' => env('CLOUD_TASKS_USE_CLOUD_RUN_JOB', false),
    'cloud_run_job_name' => env('CLOUD_RUN_JOB_NAME'),
    'cloud_run_job_region' => env('CLOUD_RUN_JOB_REGION'),
    
    // Optional: Large payload storage
    'payload_disk' => env('CLOUD_TASKS_PAYLOAD_DISK'),
    'payload_prefix' => env('CLOUD_TASKS_PAYLOAD_PREFIX', 'cloud-tasks-payloads'),
    'payload_threshold' => env('CLOUD_TASKS_PAYLOAD_THRESHOLD', 10240),
],

Breaking Changes

None. This is an additive feature - the cloud_run_job option defaults to false, preserving existing behaviour.

Tests

  • 23 new tests covering Cloud Run Job dispatch and worker functionality
  • All existing tests continue to pass (95 unit tests, 146 assertions)

Documentation

  • Added Cloud Run Jobs usage guide
  • Added IAM permissions documentation with gcloud commands

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.
@marickvantuil
Copy link
Member

This is really nice, thanks! I will review everything later.

@marickvantuil marickvantuil added the safe-to-test Pull request has access to workflow secrets to run tests label Jan 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

safe-to-test Pull request has access to workflow secrets to run tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants