### Start the container with Docker Compose Source: https://github.com/jeffersongoncalves/laravel-queue-worker/blob/main/EXAMPLE.md Starts the example Docker Compose stack and opens a bash shell inside the demo container. Run these from the project root. ```bash docker compose -f example/docker-compose.yml up -d docker compose -f example/docker-compose.yml exec demo bash ``` -------------------------------- ### Run migrations, serve, and start queue worker Source: https://github.com/jeffersongoncalves/laravel-queue-worker/blob/main/EXAMPLE.md Runs the database migrations, starts the Laravel development server on port 8000, and starts the queue worker. These commands run in the background. ```bash php artisan migrate php artisan serve --host=0.0.0.0 --port=8000 & php artisan queue:work & ``` -------------------------------- ### Install Composer and PHP extensions inside the container Source: https://github.com/jeffersongoncalves/laravel-queue-worker/blob/main/EXAMPLE.md Installs required system packages and PHP extensions (mbstring, zip) and then installs Composer globally. The base image is intentionally bare, so these are needed before scaffolding Laravel apps. ```bash apt-get update && apt-get install -y unzip libzip-dev git docker-php-ext-install mbstring zip curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer ``` -------------------------------- ### Install laravel-queue-worker via Composer Source: https://github.com/jeffersongoncalves/laravel-queue-worker/blob/main/README.md Install the package via Composer. Laravel's auto-discovery registers the service provider automatically. ```bash composer require jeffersongoncalves/laravel-queue-worker ``` -------------------------------- ### Environment setup for queue-worker Source: https://github.com/jeffersongoncalves/laravel-queue-worker/blob/main/README.md Environment variables for the package. QUEUE_WORKER_TOKEN is required and compared against the X-Laravel-Queue-Token header using hash_equals(); QUEUE_WORKER_ALLOWED_ROOT is required and must contain the environment directories. ```env QUEUE_WORKER_TOKEN=some-shared-secret-token QUEUE_WORKER_ALLOWED_ROOT=/srv/environments QUEUE_WORKER_DEDUP_WINDOW_HOURS=24 ``` -------------------------------- ### POST /api/jobs request body Source: https://github.com/jeffersongoncalves/laravel-queue-worker/blob/main/README.md Example request body for POST {route_prefix}/jobs (default /api/jobs) with header X-Laravel-Queue-Token. The payload field is an opaque string that must be exactly what Laravel's createPayload() produced in the originating environment. A successful response is 202 with {"id": ""}. ```json { "slug": "app-feature-1234", "path": "/srv/environments/app-feature-1234", "queue": "default", "delay": 0, "payload": "" } ``` -------------------------------- ### Environment .env configuration Source: https://github.com/jeffersongoncalves/laravel-queue-worker/blob/main/EXAMPLE.md Sets the queue connection to hub, the hub URL, a demo token, and the environment slug. These are demo-only values; see the Security section before real use. ```bash QUEUE_CONNECTION=hub QUEUE_CONSUMER_HUB_URL=http://127.0.0.1:8000 QUEUE_CONSUMER_TOKEN=demo-token QUEUE_CONSUMER_SLUG=app-feature-1234 ``` -------------------------------- ### Hub .env configuration Source: https://github.com/jeffersongoncalves/laravel-queue-worker/blob/main/EXAMPLE.md Sets the queue connection to database, a demo token, and the allowed root for the worker. These are demo-only values; see the Security section before real use. ```bash QUEUE_CONNECTION=database QUEUE_WORKER_TOKEN=demo-token QUEUE_WORKER_ALLOWED_ROOT=/workspace/apps ``` -------------------------------- ### Wire the environment: configure and require queue-consumer Source: https://github.com/jeffersongoncalves/laravel-queue-worker/blob/main/EXAMPLE.md Adds the local path repository for laravel-queue-consumer, requires it, and publishes its config. Run these from the environment app directory. ```bash cd /workspace/apps/app-feature-1234 composer config repositories.queue-consumer path /workspace/packages/laravel-queue-consumer composer require jeffersongoncalves/laravel-queue-consumer:@dev --no-interaction php artisan vendor:publish --tag=queue-consumer-config ``` -------------------------------- ### Publish and run queue-worker migrations Source: https://github.com/jeffersongoncalves/laravel-queue-worker/blob/main/README.md Publish and run the optional migration that adds nullable slug and display_name columns to the failed_jobs table. This migration is not run automatically and is written defensively. ```bash php artisan vendor:publish --tag=queue-worker-migrations php artisan migrate ``` -------------------------------- ### Run tests with composer test Source: https://github.com/jeffersongoncalves/laravel-queue-worker/blob/main/README.md Run the package test suite. ```bash composer test ``` -------------------------------- ### queue-worker.php configuration file Source: https://github.com/jeffersongoncalves/laravel-queue-worker/blob/main/README.md Configuration file published by the package. QUEUE_WORKER_TOKEN and QUEUE_WORKER_ALLOWED_ROOT have no defaults and are required; leaving them unset causes all requests to be rejected. php_binary_map maps an environment's PHP version to a concrete binary with no fallback. ```php return [ 'token' => env('QUEUE_WORKER_TOKEN'), 'allowed_root' => env('QUEUE_WORKER_ALLOWED_ROOT'), 'route_prefix' => env('QUEUE_WORKER_ROUTE_PREFIX', 'api'), 'route_middleware' => ['api'], 'dedup_window_hours' => env('QUEUE_WORKER_DEDUP_WINDOW_HOURS', 24), 'php_binary_map' => [ // '8.1' => '/usr/bin/php8.1', // '8.2' => '/usr/bin/php8.2', // '8.3' => '/usr/bin/php8.3', ], ]; ``` -------------------------------- ### Scaffold the two Laravel apps Source: https://github.com/jeffersongoncalves/laravel-queue-worker/blob/main/EXAMPLE.md Creates the hub app and an ephemeral environment app (app-feature-1234) using Composer. The directory name of the environment app becomes its slug. ```bash cd /workspace/apps composer create-project laravel/laravel hub --prefer-dist --no-interaction composer create-project laravel/laravel app-feature-1234 --prefer-dist --no-interaction ``` -------------------------------- ### Publish queue-worker configuration Source: https://github.com/jeffersongoncalves/laravel-queue-worker/blob/main/README.md Publish the package configuration file to config/queue-worker.php. ```bash php artisan vendor:publish --tag=queue-worker-config ``` -------------------------------- ### Map PHP binary in config/queue-worker.php Source: https://github.com/jeffersongoncalves/laravel-queue-worker/blob/main/EXAMPLE.md Maps the container's PHP version (8.3) to its binary path. Confirm the version with `php -v` before using. ```php 'php_binary_map' => [ '8.3' => '/usr/local/bin/php', ], ``` -------------------------------- ### Wire the hub: configure and require queue-worker Source: https://github.com/jeffersongoncalves/laravel-queue-worker/blob/main/EXAMPLE.md Adds the local path repository for laravel-queue-worker, requires it, and publishes its config. Run these from the hub app directory. ```bash cd /workspace/apps/hub composer config repositories.queue-worker path /workspace/packages/laravel-queue-worker composer require jeffersongoncalves/laravel-queue-worker:@dev --no-interaction php artisan vendor:publish --tag=queue-worker-config ``` -------------------------------- ### Dispatch a job from the environment Source: https://github.com/jeffersongoncalves/laravel-queue-worker/blob/main/EXAMPLE.md Uses Laravel Tinker to dispatch a closure that writes a timestamp to a file. This job is sent to the hub over HTTP. ```bash php artisan tinker --execute="dispatch(fn () => file_put_contents('/tmp/ran-from-app-feature-1234', now()));" ``` -------------------------------- ### Confirm the job ran Source: https://github.com/jeffersongoncalves/laravel-queue-worker/blob/main/EXAMPLE.md Checks the file created by the dispatched closure. A timestamp proves the job travelled from the environment to the hub and back. ```bash cat /tmp/ran-from-app-feature-1234 ``` -------------------------------- ### Cleanup: exit and tear down the container Source: https://github.com/jeffersongoncalves/laravel-queue-worker/blob/main/EXAMPLE.md Exits the container shell and stops/removes the Docker Compose stack, including volumes. ```bash exit docker compose -f example/docker-compose.yml down -v ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.