PHP code example of stackkit / laravel-google-cloud-tasks-queue

1. Go to this page and download the library: Download stackkit/laravel-google-cloud-tasks-queue library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

stackkit / laravel-google-cloud-tasks-queue example snippets


'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
],

'disable_task_handler' => env('CLOUD_TASKS_DISABLE_TASK_HANDLER', false),

'cloudtasks' => [
    'driver' => 'cloudtasks',
    'project' => env('CLOUD_TASKS_PROJECT'),
    'location' => env('CLOUD_TASKS_LOCATION'),
    'queue' => env('CLOUD_TASKS_QUEUE', 'default'),
    
    // Cloud Run Job configuration
    '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'), // defaults to location
    'service_account_email' => env('CLOUD_TASKS_SERVICE_EMAIL'),
    
    // Optional: Store large payloads (>10KB) in filesystem
    'payload_disk' => env('CLOUD_TASKS_PAYLOAD_DISK'), // Laravel disk name
    'payload_prefix' => env('CLOUD_TASKS_PAYLOAD_PREFIX', 'cloud-tasks-payloads'),
    'payload_threshold' => env('CLOUD_TASKS_PAYLOAD_THRESHOLD', 10240), // bytes
],

use Stackkit\LaravelGoogleCloudTasksQueue\CloudTasksQueue;

CloudTasksQueue::setTaskHeadersUsing(static fn() => [
  'X-My-Header' => 'My-Value',
]);

CloudTasksQueue::setTaskHeadersUsing(static fn(array $payload) => [
  'X-My-Header' => $payload['displayName'],
]);

CloudTasksQueue::configureHandlerUrlUsing(static fn() => 'https://example.com/my-url');

CloudTasksQueue::configureHandlerUrlUsing(static fn(MyJob $job) => 'https://example.com/my-url/' . $job->something());

use Stackkit\LaravelGoogleCloudTasksQueue\IncomingTask;

CloudTasksQueue::configureWorkerOptionsUsing(function (IncomingTask $task) {
    $queueTries = [
        'high' => 5,
        'low' => 1,
    ];

    return new WorkerOptions(maxTries: $queueTries[$task->queue()] ?? 1);
});

'client_options' => [
    'credentials' => '/path/to/credentials.json',
]

'client_options' => [
    // Custom options here
]
console
php artisan vendor:publish --tag=cloud-tasks
bash
php artisan cloud-tasks:work-job
ini
zend.max_allowed_stack_size=-1