### Install Vantage and Publish Configuration Source: https://github.com/storviaio/vantage/blob/main/README.md Install the Vantage package using Composer and publish its configuration file. This is the first step to setting up Vantage for your Laravel project. ```bash composer require storviaio/vantage php artisan vendor:publish --tag=vantage-config php artisan migrate ``` -------------------------------- ### Example Unit Test Source: https://github.com/storviaio/vantage/blob/main/tests/README.md A basic unit test demonstrating the creation of a VantageJob model and assertion of its status. ```php it('does something', function () { $job = VantageJob::create([ 'uuid' => Str::uuid(), 'job_class' => 'App\\Jobs\\TestJob', 'status' => 'processing', ]); expect($job->status)->toBe('processing'); }); ``` -------------------------------- ### Example Feature Test Source: https://github.com/storviaio/vantage/blob/main/tests/README.md A basic feature test making a GET request to the /vantage/jobs endpoint and asserting a 200 status code. ```php it('handles a feature', function () { $response = $this->get('/vantage/jobs'); $response->assertStatus(200); }); ``` -------------------------------- ### GitHub Actions CI/CD Integration Source: https://github.com/storviaio/vantage/blob/main/tests/README.md Example of how to integrate the 'composer test' command into a GitHub Actions workflow for CI/CD. ```yaml # Example GitHub Actions - name: Run tests run: composer test ``` -------------------------------- ### Load Test Scenario: Run Queue Worker Source: https://github.com/storviaio/vantage/blob/main/tests/README.md Start a queue worker to process generated jobs. Configure retries and timeout. ```bash php artisan queue:work --tries=3 --timeout=300 ``` -------------------------------- ### Programmatic Access to Statistics Source: https://github.com/storviaio/vantage/blob/main/README.md Fetch monitoring statistics such as total jobs, processed, failed, and success rate. You can specify a start date to get statistics for a particular period. ```php use Storvia\Vantage\Facades\Vantage; // Get statistics $stats = Vantage::statistics(startDate: now()->subDays(7)); // Returns: ['total' => 1000, 'processed' => 950, 'failed' => 50, 'processing' => 0, 'success_rate' => 95.0] ``` -------------------------------- ### Customize 'viewVantage' Gate Source: https://github.com/storviaio/vantage/blob/main/README.md Override the default 'viewVantage' gate in your AppServiceProvider to implement custom access control for the Vantage dashboard. This example shows how to allow only admin users. ```php use Illuminate\Support\Facades\Gate; public function boot(): void { Gate::define('viewVantage', function ($user = null) { // Only allow admins return optional($user)->isAdmin(); // Or any other custom logic // return $user && $user->hasRole('developer'); }); } ``` -------------------------------- ### Publish Vantage Configuration Source: https://github.com/storviaio/vantage/blob/main/README.md Use this command to publish the Vantage configuration file if it's not already present. This allows for customization of package settings. ```bash php artisan vendor:publish --tag=vantage-config ``` -------------------------------- ### Run Project Tests Source: https://github.com/storviaio/vantage/blob/main/CONTRIBUTING.md Execute the project's test suite using Composer. Ensure all tests pass before submitting changes. ```bash composer test ``` -------------------------------- ### Vantage Facade Method Signatures Source: https://github.com/storviaio/vantage/blob/main/README.md Reference for available methods on the Vantage facade, including their parameters and return types. This provides a quick overview for programmatic usage. ```php use Storvia\Vantage\Facades\Vantage; // Available Facade Methods: // - queueDepth(?string $queue = null) // - jobsByStatus(string $status, int $limit = 50) // - failedJobs(int $limit = 50) // - processingJobs(int $limit = 50) // - jobsByTag(string $tag, int $limit = 50) // - statistics(?string $startDate = null) // - retryJob(int $jobId) // - cleanupStuckJobs(int $hoursOld = 24) // - pruneOldJobs(int $daysOld = 30) // - logger() // - enable() / disable() / enabled() ``` -------------------------------- ### Load Test Scenario: Monitor Database with Tinker Source: https://github.com/storviaio/vantage/blob/main/tests/README.md Use Artisan Tinker to monitor the count of total, processed, and failed jobs in the database. ```bash php artisan tinker >>> \Storvia\Vantage\Models\VantageJob::count() >>> \Storvia\Vantage\Models\VantageJob::where('status', 'processed')->count() >>> \Storvia\Vantage\Models\VantageJob::where('status', 'failed')->count() ``` -------------------------------- ### Perform Static Analysis Source: https://github.com/storviaio/vantage/blob/main/CONTRIBUTING.md Run static analysis tools on the codebase using Composer. This helps identify potential issues and enforce code quality. ```bash composer analyse ``` -------------------------------- ### Full Load Test Scenario: Generate Jobs Source: https://github.com/storviaio/vantage/blob/main/tests/README.md Generate 5000 test jobs with specific success rates, tags, durations, and batch sizes for a comprehensive load test. ```bash php artisan vantage:generate-test-jobs \ --count=5000 \ --success-rate=80 \ --tags=load-test,production,stress-test \ --duration-min=50 \ --duration-max=2000 \ --batch-size=100 ``` -------------------------------- ### Generate Test Jobs with Batched Dispatch Source: https://github.com/storviaio/vantage/blob/main/tests/README.md Generate test jobs and dispatch them in smaller, configurable batches. ```bash php artisan vantage:generate-test-jobs --count=1000 --batch-size=25 ``` -------------------------------- ### Load Test Scenario: Generate Jobs Source: https://github.com/storviaio/vantage/blob/main/tests/README.md Generate 1000 test jobs with an 85% success rate for load testing. ```bash php artisan vantage:generate-test-jobs --count=1000 --success-rate=85 ``` -------------------------------- ### Publish Vantage Migrations Source: https://github.com/storviaio/vantage/blob/main/README.md Publish the Vantage database migrations if you need to manually manage them. Typically, migrations are loaded automatically. ```bash php artisan vendor:publish --tag=vantage-migrations ``` -------------------------------- ### Run Tests with Coverage Source: https://github.com/storviaio/vantage/blob/main/tests/README.md Execute tests and generate code coverage reports using Pest. ```bash ./vendor/bin/pest --coverage ``` -------------------------------- ### Generate Default Test Jobs Source: https://github.com/storviaio/vantage/blob/main/tests/README.md Generate 100 test jobs for load testing using the artisan command. ```bash php artisan vantage:generate-test-jobs ``` -------------------------------- ### Publish Vantage Views Source: https://github.com/storviaio/vantage/blob/main/README.md Optionally publish the Vantage views if you need to customize the web interface. This allows for visual modifications to the monitoring dashboard. ```bash php artisan vendor:publish --tag=vantage-views ``` -------------------------------- ### Generate Test Jobs with Custom Tags Source: https://github.com/storviaio/vantage/blob/main/tests/README.md Generate test jobs and assign custom tags for filtering and organization. ```bash php artisan vantage:generate-test-jobs --count=500 --tags=load-test,production,email ``` -------------------------------- ### Format Code Style Source: https://github.com/storviaio/vantage/blob/main/CONTRIBUTING.md Apply code style conventions using Composer and Laravel Pint. This command formats the code according to PSR-12 standards. ```bash composer format ``` -------------------------------- ### Programmatic Access - Vantage Facade Source: https://github.com/storviaio/vantage/blob/main/README.md Utilize the Vantage facade for programmatic access to queue monitoring data and management functions. ```APIDOC ## Vantage Facade Methods ### Description Provides a convenient facade for easy programmatic access to queue monitoring data and management functions. ### Usage ```php use Storvia\Vantage\Facades\Vantage; ``` ### Available Methods - `queueDepth(?string $queue = null)`: Get queue depths for all or specific queues. - `jobsByStatus(string $status, int $limit = 50)`: Get jobs by status (processing, processed, failed). - `failedJobs(int $limit = 50)`: Get failed jobs. - `processingJobs(int $limit = 50)`: Get currently processing jobs. - `jobsByTag(string $tag, int $limit = 50)`: Get jobs filtered by tag. - `statistics(?string $startDate = null)`: Get dashboard statistics. Returns an array with 'total', 'processed', 'failed', 'processing', and 'success_rate'. - `retryJob(int $jobId)`: Retry a failed job programmatically. - `cleanupStuckJobs(int $hoursOld = 24)`: Clean up stuck processing jobs older than the specified hours. - `pruneOldJobs(int $daysOld = 30)`: Prune old job records older than the specified days. - `logger()`: Get the VantageLogger instance. - `enable()`: Enable the Vantage package. - `disable()`: Disable the Vantage package. - `enabled()`: Check if the Vantage package is enabled. ``` -------------------------------- ### Composer Test Script Configuration Source: https://github.com/storviaio/vantage/blob/main/tests/README.md The 'test' script in composer.json is configured to run Pest with parallel execution enabled. ```json "scripts": { "test": "pest -p" } ``` -------------------------------- ### Specify Database Connection for Vantage Source: https://github.com/storviaio/vantage/blob/main/README.md Configure the database connection Vantage should use for storing queue job runs by setting this environment variable. This is crucial for applications with multiple database connections. ```env VANTAGE_DATABASE_CONNECTION=mysql ``` -------------------------------- ### Vantage Environment Variables Source: https://github.com/storviaio/vantage/blob/main/README.md Configure the Vantage package's behavior using environment variables. Key settings include enabling/disabling the package, database connection, authentication, payload storage, telemetry, data retention, notifications, and route configuration. ```env # Master switch - Enable/disable entire package (default: true) VANTAGE_ENABLED=true # Database connection for vantage_jobs table (optional) VANTAGE_DATABASE_CONNECTION=mysql # Authentication (default: true) VANTAGE_AUTH_ENABLED=true # Payload storage (default: true) VANTAGE_STORE_PAYLOAD=true # Telemetry (default: true) VANTAGE_TELEMETRY_ENABLED=true VANTAGE_TELEMETRY_SAMPLE_RATE=1.0 VANTAGE_TELEMETRY_CPU=true # Data retention (default: 14 days) VANTAGE_RETENTION_DAYS=14 # Notifications VANTAGE_NOTIFY_EMAIL=admin@example.com VANTAGE_SLACK_WEBHOOK=https://hooks.slack.com/services/... # Routes (default: true) VANTAGE_ROUTES=true # Change the base URL path for the dashboard (default: vantage) VANTAGE_ROUTE_PREFIX=vantage # Logging (default: true) VANTAGE_LOGGING_ENABLED=true ``` -------------------------------- ### Create Test Jobs with Model Factory Source: https://github.com/storviaio/vantage/blob/main/README.md Use the VantageJob factory to create various test job instances, including specific states, tagged jobs, jobs on specific queues, retry chains, and jobs with custom class names. ```php use Storvia\Vantage\Models\VantageJob; // Create test jobs $job = VantageJob::factory()->create(); // Create specific job states $failedJob = VantageJob::factory()->failed()->create(); $processingJob = VantageJob::factory()->processing()->create(); $processedJob = VantageJob::factory()->processed()->create(); // Create jobs with tags $taggedJob = VantageJob::factory() ->withTags(['email', 'notification']) ->create(); // Create jobs on specific queues $highPriorityJob = VantageJob::factory() ->onQueue('high') ->create(); // Create a retry chain $originalJob = VantageJob::factory()->failed()->create(); $retryJob = VantageJob::factory() ->retriedFrom($originalJob->id) ->create(); // Create jobs with specific class names $emailJob = VantageJob::factory() ->jobClass('App\\Jobs\\SendEmailJob') ->create(); ``` -------------------------------- ### Generate Test Jobs with Custom Count and Success Rate Source: https://github.com/storviaio/vantage/blob/main/tests/README.md Generate a specified number of test jobs with a defined success rate. ```bash php artisan vantage:generate-test-jobs --count=1000 --success-rate=90 ``` -------------------------------- ### Run Tests in Parallel Source: https://github.com/storviaio/vantage/blob/main/tests/README.md Execute tests in parallel using Pest for faster execution. ```bash ./vendor/bin/pest -p ``` -------------------------------- ### Web Interface - Dashboard Source: https://github.com/storviaio/vantage/blob/main/README.md Access the main monitoring dashboard at the /vantage path to view system statistics, queue depths, trends, and recent job information. ```APIDOC ## Dashboard ### Description Overview of your queue system including statistics cards, queue depth monitoring, success rate trends, top failing jobs, top exceptions, recent jobs, recent batches, and time period filters. ### Endpoint `/vantage` ### Parameters #### Query Parameters - **startDate** (string) - Optional - Start date for viewing data (e.g., 'last hour', '7 days'). ### Response #### Success Response (200) - **Statistics Cards**: Total jobs, processed, failed, processing, success rate. - **Queue Depth Monitoring**: Real-time pending job counts per queue with health status. - **Success Rate Trend Chart**: Visual representation of job success/failure over time. - **Top Failing Jobs**: List of job classes that fail most often. - **Top Exceptions**: Most common error types with counts. - **Recent Jobs Table**: Latest 20 jobs with status, duration, and quick actions. - **Recent Batches**: Track Laravel job batches with success/failure rates. ``` -------------------------------- ### Generate Test Jobs with Variable Duration Source: https://github.com/storviaio/vantage/blob/main/tests/README.md Generate test jobs with durations ranging between specified minimum and maximum values. ```bash php artisan vantage:generate-test-jobs --count=200 --duration-min=10 --duration-max=10000 ``` -------------------------------- ### Run Specific Test File Source: https://github.com/storviaio/vantage/blob/main/tests/README.md Execute a specific test file using the Pest test runner. ```bash ./vendor/bin/pest tests/Unit/VantageJobTest.php ``` -------------------------------- ### Schedule Automatic Job Pruning Source: https://github.com/storviaio/vantage/blob/main/README.md Configure the application's scheduler to automatically prune old jobs daily. Use `--force` for unattended execution and `--keep-processing` to preserve active jobs. The retention period can be set via configuration. ```php protected function schedule(Schedule $schedule) { // Prune jobs older than retention_days config (uses VANTAGE_RETENTION_DAYS or default: 14 days) // --force skips confirmation prompt (required for scheduled tasks) // --keep-processing preserves active jobs $schedule->command('vantage:prune --force --keep-processing') ->daily() ->at('02:00'); } ``` -------------------------------- ### Web Interface - Jobs List Source: https://github.com/storviaio/vantage/blob/main/README.md Access the jobs list at /vantage/jobs to view and filter all jobs with advanced filtering capabilities. ```APIDOC ## Jobs List ### Description View and filter all jobs with advanced filtering options including status, queue name, job class, tags, and date range. Features a popular tags cloud and pagination. ### Endpoint `/vantage/jobs` ### Parameters #### Query Parameters - **status** (string) - Optional - Filter by job status (processed, failed, processing). - **queue** (string) - Optional - Filter by queue name. - **job_class** (string) - Optional - Filter by job class (partial match supported). - **tags** (string) - Optional - Filter by tags (supports multiple tags with "all" or "any" mode). - **startDate** (string) - Optional - Start date for filtering. - **endDate** (string) - Optional - End date for filtering. ### Response #### Success Response (200) - **Jobs**: A paginated list of jobs (50 per page) with details like ID, class name, queue, tags, and status. ``` -------------------------------- ### Run Tests with Pest Directly Source: https://github.com/storviaio/vantage/blob/main/tests/README.md Execute tests directly using the Pest test runner. ```bash ./vendor/bin/pest ``` -------------------------------- ### Programmatic Access to Failed Jobs Source: https://github.com/storviaio/vantage/blob/main/README.md Fetch a list of failed jobs, with an option to limit the number of results returned. This helps in identifying and managing job failures. ```php use Storvia\Vantage\Facades\Vantage; // Get failed jobs $failedJobs = Vantage::failedJobs(limit: 100); ``` -------------------------------- ### Web Interface - Job Details Source: https://github.com/storviaio/vantage/blob/main/README.md View comprehensive information for a specific job at /vantage/jobs/{id}. ```APIDOC ## Job Details ### Description Provides comprehensive information for a specific job, including basic details, timing, exception information for failed jobs, payload, tags, and retry chain. ### Endpoint `/vantage/jobs/{id}` ### Parameters #### Path Parameters - **id** (integer) - Required - The ID of the job to view. ### Response #### Success Response (200) - **Basic Information**: Status, UUID, queue, connection, job class. - **Timing**: Start time, finish time, duration. - **Exception Details**: Full exception class, message, and stack trace (for failed jobs). - **Payload**: Complete job payload in JSON format. - **Tags**: All tags associated with the job. - **Retry Chain**: View original job and all retry attempts. - **Quick Actions**: Retry failed jobs directly from the details page. ``` -------------------------------- ### Programmatic Check if Vantage is Enabled Source: https://github.com/storviaio/vantage/blob/main/README.md Check the current enabled status of the Vantage package programmatically. This allows for conditional execution of monitoring-related logic. ```php use Storvia\Vantage\Facades\Vantage; // Check if Vantage is enabled if (Vantage::enabled()) { // Monitor critical jobs } ``` -------------------------------- ### Implement 'ShouldNotBeTracked' Interface Source: https://github.com/storviaio/vantage/blob/main/README.md Jobs can be excluded from Vantage tracking by implementing the 'ShouldNotBeTracked' interface. This provides an alternative to the 'exclude_jobs' configuration array. ```php use Storvia\Vantage\Contracts\ShouldNotBeTracked; class MyNoisyJob implements ShouldQueue, ShouldNotBeTracked { public function handle(): void { ... } } ``` -------------------------------- ### Command Line - Retry Failed Jobs Source: https://github.com/storviaio/vantage/blob/main/README.md Retry a specific failed job using the Artisan command. ```APIDOC ## Retry Failed Jobs (CLI) ### Description Retry a specific failed job using the Artisan command line interface. ### Method `php artisan vantage:retry {job_id}` ### Parameters #### Path Parameters - **job_id** (integer) - Required - The ID of the failed job to retry. ``` -------------------------------- ### Retry a Failed Job via Artisan Command Source: https://github.com/storviaio/vantage/blob/main/README.md Use the `vantage:retry` Artisan command to retry a specific failed job by its ID. Alternatively, failed jobs can be retried directly from the web interface. ```bash php artisan vantage:retry {job_id} ``` -------------------------------- ### Prune Old Jobs Command Source: https://github.com/storviaio/vantage/blob/main/README.md Delete old job records from the database to manage storage. Options include specifying the retention period in days or hours, filtering by status, keeping processing jobs, and previewing deletions with `--dry-run` or `--force` to skip confirmation. ```bash php artisan vantage:prune [--days=30] [--hours=] [--status=] [--keep-processing] [--dry-run] [--force] ``` ```bash # Prune jobs older than 30 days (uses config default) php artisan vantage:prune ``` ```bash # Prune jobs older than 7 days, keeping processing jobs php artisan vantage:prune --days=7 --keep-processing ``` ```bash # Prune only failed jobs older than 14 days php artisan vantage:prune --days=14 --status=failed ``` ```bash # Preview what would be deleted php artisan vantage:prune --days=30 --dry-run ``` ```bash # Prune jobs older than 12 hours php artisan vantage:prune --hours=12 --force ``` -------------------------------- ### Programmatic Access to Queue Depth Source: https://github.com/storviaio/vantage/blob/main/README.md Retrieve the number of pending jobs for all queues or a specific queue using the Vantage facade. This is useful for monitoring queue backlogs. ```php use Storvia\Vantage\Facades\Vantage; // Get queue depth for all queues $depths = Vantage::queueDepth(); ``` -------------------------------- ### Exclude Specific Jobs from Monitoring Source: https://github.com/storviaio/vantage/blob/main/README.md Add jobs to the 'exclude_jobs' configuration array to prevent them from being tracked by Vantage. This is useful for noisy or non-essential jobs. ```php 'exclude_jobs' => [ App\Jobs\SomeNoisyJob::class, ], ``` -------------------------------- ### Programmatic Access to Jobs by Tag Source: https://github.com/storviaio/vantage/blob/main/README.md Retrieve jobs associated with a specific tag, with an option to limit the number of results. This is useful for filtering jobs related to particular functionalities. ```php use Storvia\Vantage\Facades\Vantage; // Get jobs by tag $emailJobs = Vantage::jobsByTag('email', limit: 50); ``` -------------------------------- ### Programmatic Cleanup of Stuck Jobs Source: https://github.com/storviaio/vantage/blob/main/README.md Clean up jobs that have been stuck in the processing state for a specified number of hours. This helps in resolving issues with jobs that do not complete. ```php use Storvia\Vantage\Facades\Vantage; // Clean up stuck jobs older than 24 hours $cleaned = Vantage::cleanupStuckJobs(hoursOld: 24); ``` -------------------------------- ### Programmatic Retry of a Failed Job Source: https://github.com/storviaio/vantage/blob/main/README.md Retry a specific failed job using its ID programmatically. This method is an alternative to using the Artisan command or the web interface. ```php use Storvia\Vantage\Facades\Vantage; // Retry a failed job programmatically Vantage::retryJob($jobId); ``` -------------------------------- ### Programmatic Pruning of Old Job Records Source: https://github.com/storviaio/vantage/blob/main/README.md Remove old job records from the database to manage storage space. You can specify the number of days after which jobs should be pruned. ```php use Storvia\Vantage\Facades\Vantage; // Prune old jobs $deleted = Vantage::pruneOldJobs(daysOld: 30); ``` -------------------------------- ### Cleanup Stuck Jobs Command Source: https://github.com/storviaio/vantage/blob/main/README.md Remove jobs that are stuck in the 'processing' state, which can occur if a job was interrupted. The `--timeout` option specifies how long a job must be processing to be considered stuck, and `--dry-run` allows previewing without deletion. ```bash php artisan vantage:cleanup-stuck [--timeout=1] [--dry-run] ``` ```bash # Clean up jobs stuck for more than 2 hours php artisan vantage:cleanup-stuck --timeout=2 ``` ```bash # Preview what would be cleaned php artisan vantage:cleanup-stuck --dry-run ``` -------------------------------- ### Disable Vantage Package Source: https://github.com/storviaio/vantage/blob/main/README.md Set this environment variable to 'false' to completely disable the Vantage package. This stops job tracking, route registration, and event listeners, which is useful for staging environments. ```env VANTAGE_ENABLED=false ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.