### Install Moox Jobs with Interactive Installer Source: https://context7.com/mooxphp/jobs/llms.txt Use this command for a minimal fresh install. Follow the prompts to publish configuration, migrations, and register plugins. ```bash # Minimal fresh install composer require moox/jobs php artisan mooxjobs:install # Follow the interactive prompts to publish config, migrations, and register plugins. # If using the full Moox application, one command installs everything: php artisan moox:install ``` -------------------------------- ### Install All Moox Packages Source: https://github.com/mooxphp/jobs/blob/main/README.md Use this command to install all Moox packages and run their migrations simultaneously. This is the recommended installation method when using the Moox application. ```bash php artisan moox:install ``` -------------------------------- ### Install Moox Jobs with Filament Install Source: https://github.com/mooxphp/jobs/blob/main/README.md This installation process includes Filament's auto-installation. Ensure you have a MySQL database set up. ```bash composer create-project laravel/laravel moox-test cd moox-test mysqladmin -u root -p create moox-test composer require filament/filament composer require moox/jobs php artisan mooxjobs:install ``` -------------------------------- ### Quick Laravel Setup for Demo Source: https://github.com/mooxphp/jobs/blob/main/README.md Steps to quickly set up a new Laravel project with Filament for demonstrating Moox Jobs. ```bash composer create-project laravel/laravel moox-jobs-demo composer require filament/filament php artisan filament:install --panels php artisan make:filament-user ``` -------------------------------- ### Start Laravel Scheduler Source: https://github.com/mooxphp/jobs/blob/main/README.md Use this command to start the Laravel Scheduler on shared hosting. Ensure you have SSH access. ```bash php artisan schedule:work ``` -------------------------------- ### Manual Installation of Moox Jobs Source: https://github.com/mooxphp/jobs/blob/main/README.md Manually install the Moox Jobs package by requiring it via Composer and then publishing and running its specific migrations. This is an alternative to using the unified installer. ```bash composer require moox/jobs php artisan vendor:publish --tag="jobs-manager-migration" php artisan vendor:publish --tag="jobs-batch-migration" php artisan vendor:publish --tag="jobs-queue-migration" php artisan vendor:publish --tag="jobs-manager-foreigns-migration" ``` -------------------------------- ### Start Queue Worker Source: https://github.com/mooxphp/jobs/blob/main/README.md Use this command to start the queue worker on shared hosting. Ensure you have SSH access. ```bash php artisan queue:work ``` -------------------------------- ### Install Moox Jobs with Laravel Source: https://github.com/mooxphp/jobs/blob/main/README.md Use this command to set up Moox Jobs in a new Laravel project. It includes installing Filament and its user provider. ```bash composer create-project laravel/laravel moox-test cd moox-test mysqladmin -u root -p create moox-test composer require filament/filament php artisan filament:install --panels php artisan make:filament-user composer require moox/jobs php artisan mooxjobs:install ``` -------------------------------- ### Install Moox Jobs with Filament Require Source: https://github.com/mooxphp/jobs/blob/main/README.md This command installs Moox Jobs and requires Filament separately. It assumes Filament will be installed manually. ```bash composer create-project laravel/laravel moox-test cd moox-test mysqladmin -u root -p create moox-test composer require moox/jobs php artisan mooxjobs:install ``` -------------------------------- ### Test Moox Jobs Installation Source: https://github.com/mooxphp/jobs/blob/main/README.md This script details the steps for testing the installation of Moox Jobs, including cloning the monorepo and copying necessary files. It's designed for comprehensive testing across different environments. ```bash composer create-project laravel/laravel moox-test cd moox-test mysqladmin -u root -p create moox-test composer require filament/filament php artisan filament:install --panels php artisan make:filament-user composer require moox/jobs php artisan mooxjobs:install mkdir monorepo cd monorepo git clone https://github.com/mooxphp/moox cp app/Jobs/* ../app/Jobs/ cp app/Console/Commands/* ../app/Console/Commands/ cp app/Console/kernel.php ../app/Console/kernel.php # final steps depend on the target system composer require laravel/horizon # Forge only php artisan queue:work php artisan schedule:work ``` -------------------------------- ### Install Moox Jobs Package Only Source: https://github.com/mooxphp/jobs/blob/main/README.md Install only the Moox Jobs package if you are not using the full Moox application. This involves requiring the package via Composer and then running its specific install command. ```bash composer require moox/jobs php artisan mooxjobs:install ``` -------------------------------- ### Dispatch a Job Batch Source: https://context7.com/mooxphp/jobs/llms.txt Dispatch a new job batch using the Bus facade. This example shows how to group multiple jobs under a single batch name, allow failures, and then dispatch them. The resulting batch ID can be used to track the batch in the JobsBatchesResource. ```php use Illuminate\Support\Facades\Bus; use App\Jobs\ProcessOrderJob; $batch = Bus::batch([ new ProcessOrderJob(101), new ProcessOrderJob(102), new ProcessOrderJob(103), ])->name('Process Orders — Batch #' . date('Ymd')) ->allowFailures() ->dispatch(); // The batch is now visible at /admin/job-batches // $batch->id holds the UUID shown in the resource ``` -------------------------------- ### Customize Job Display Name Source: https://github.com/mooxphp/jobs/blob/main/README.md Override the default job name (class name) by implementing the `displayName` method in your job class. This example shows how to include the start time in the display name. ```php use Illuminate\support\Carbon; ... public function displayName() { $now = Carbon::now(); return "Demo Job | Started: " . $now; } ``` -------------------------------- ### Example JobManagerPolicy Source: https://context7.com/mooxphp/jobs/llms.txt An example policy for JobManager that grants access if the user has the 'admin' role or the 'manage_jobs' permission. This demonstrates how to implement custom authorization logic. ```php // app/Policies/JobManagerPolicy.php namespace App\Policies; use App\Models\User; use Illuminate\Auth\Access\HandlesAuthorization; class JobManagerPolicy { use HandlesAuthorization; public function viewAny(User $user): bool { return $user->hasRole('admin') || $user->can('manage_jobs'); } } ``` -------------------------------- ### Register Moox Jobs Plugins in Filament Panel Source: https://context7.com/mooxphp/jobs/llms.txt Register the JobsPlugin, JobsWaitingPlugin, JobsFailedPlugin, and JobsBatchesPlugin in your Filament panel provider to enable job monitoring features. This example shows minimal registration using default configurations. ```php // app/Providers/Filament/AdminPanelProvider.php use Moox\Jobs\Moox\Plugins\JobsPlugin; use Moox\Jobs\Moox\Plugins\JobsWaitingPlugin; use Moox\Jobs\Moox\Plugins\JobsFailedPlugin; use Moox\Jobs\Moox\Plugins\JobsBatchesPlugin; public function panel(Panel $panel): Panel { return $panel // ... other configuration ... ->plugins([ // Minimal — uses config/jobs.php defaults JobsPlugin::make(), JobsWaitingPlugin::make(), JobsFailedPlugin::make(), JobsBatchesPlugin::make(), ]); } ``` -------------------------------- ### Run Database Migrations Source: https://github.com/mooxphp/jobs/blob/main/README.md After creating the migration files, execute this command to apply them to your database. ```bash php artisan migrate ``` -------------------------------- ### Create Queue Migration Tables Source: https://github.com/mooxphp/jobs/blob/main/README.md Run these commands to create the necessary database tables for queue, failed jobs, and job batches. ```bash php artisan queue:table php artisan queue:failed-table php artisan queue:batches-table ``` -------------------------------- ### Demo Job Implementation Source: https://github.com/mooxphp/jobs/blob/main/README.md This PHP class demonstrates a basic job with progress tracking. It sets job parameters like tries, timeout, and max exceptions, and simulates progress updates within the handle method. Create this file in app/Jobs/. ```php tries = 10; $this->timeout = 120; $this->maxExceptions = 3; $this->backoff = 240; } public function handle() { $count = 0; $steps = 10; $final = 100; while ($count < $final) { $this->setProgress($count); $count = $count + $steps; sleep(10); } } } ``` -------------------------------- ### Enable and Configure Shared Hosting HTTP Endpoint Source: https://context7.com/mooxphp/jobs/llms.txt Configure environment variables to enable the shared hosting HTTP endpoint for triggering queue work cycles. This requires setting `SHARED_HOSTING_ENABLED` to true and providing a secure `SHARED_HOSTING_TOKEN`. ```bash # Enable in .env / config/core.php: SHARED_HOSTING_ENABLED=true SHARED_HOSTING_TOKEN=my-very-secret-token ``` -------------------------------- ### Publish Moox Jobs Assets Individually Source: https://context7.com/mooxphp/jobs/llms.txt Use these vendor:publish commands for granular control over publishing migrations and configuration files. Ensure Laravel's native queue tables are created and migrated. ```bash # Publish the jobs config php artisan vendor:publish --tag="jobs-config" # Publish the Moox job_manager migration php artisan vendor:publish --tag="jobs-manager-migration" # Publish the job_batch_manager migration php artisan vendor:publish --tag="jobs-batch-migration" # Publish the job_queue_workers migration php artisan vendor:publish --tag="jobs-queue-migration" # Publish the foreign-key migration php artisan vendor:publish --tag="jobs-manager-foreigns-migration" # Create Laravel's native queue tables (database driver only) php artisan queue:table php artisan queue:failed-table php artisan queue:batches-table php artisan migrate ``` -------------------------------- ### Cleanup Test Database and Directory Source: https://github.com/mooxphp/jobs/blob/main/README.md Use these commands to remove the test database and project directory after testing. Ensure you are in the correct parent directory before executing. ```bash mysql -u root -p drop database moox-test ``` ```bash cd .. ``` ```bash rm -Rf moox-test ``` -------------------------------- ### Dispatch a Demo Job Command Source: https://github.com/mooxphp/jobs/blob/main/README.md This PHP command dispatches a demo job. Ensure the DemoJobCommand.php file is placed in app/Console/Commands. Run 'php artisan moox:demojob' to dispatch. ```php info('Starting Moox Demo Job'); DemoJob::dispatch(); $this->info('Moox Demo Job finished'); } } ``` -------------------------------- ### Configure Jobs Plugin in config/jobs.php Source: https://context7.com/mooxphp/jobs/llms.txt Define resource toggles and automatic pruning settings for stale `job_manager` rows directly in the configuration file. ```php // config/jobs.php return [ 'resources' => [ 'jobs' => [ 'enabled' => true, 'label' => 'Job', 'plural_label' => 'Jobs', 'navigation_group' => 'Job manager', 'navigation_icon' => 'heroicon-o-play', 'navigation_count_badge' => true, 'resource' => \Moox\Jobs\Resources\JobsResource::class, ], 'jobs_waiting' => [ 'enabled' => true, 'label' => 'Job waiting', 'plural_label' => 'Jobs waiting', 'navigation_group' => 'Job manager', 'navigation_icon' => 'heroicon-o-pause', 'navigation_count_badge' => true, 'resource' => \Moox\Jobs\Resources\JobsWaitingResource::class, ], 'failed_jobs' => [ 'enabled' => true, 'label' => 'Failed Job', 'plural_label' => 'Failed Jobs', 'navigation_group' => 'Job manager', 'navigation_icon' => 'heroicon-o-exclamation-triangle', 'navigation_count_badge' => true, 'resource' => \Moox\Jobs\Resources\JobsFailedResource::class, ], 'job_batches' => [ 'enabled' => true, 'label' => 'Job Batch', 'plural_label' => 'Job Batches', 'navigation_group' => 'Job manager', 'navigation_icon' => 'heroicon-o-inbox-stack', 'navigation_count_badge' => true, 'resource' => \Moox\Jobs\Resources\JobBatchesResource::class, ], ], 'pruning' => [ 'enabled' => true, 'retention_days' => 7, ], ]; ``` -------------------------------- ### Configure Jobs Plugin with Fluent Methods Source: https://context7.com/mooxphp/jobs/llms.txt Override plugin labels, icons, and pruning settings using chainable methods. This allows for per-panel customization without modifying the config file. ```php ->plugins([ JobsPlugin::make() ->label('Job run') ->pluralLabel('Job runs') ->enableNavigation(true) ->navigationIcon('heroicon-o-face-smile') ->navigationGroup('Queues & Workers') ->navigationSort(5) ->navigationCountBadge(true) ->enablePruning(true) ->pruningRetention(14), // keep records for 14 days JobsWaitingPlugin::make() ->label('Waiting') ->pluralLabel('Jobs waiting') ->navigationIcon('heroicon-o-clock') ->navigationGroup('Queues & Workers') ->navigationCountBadge(true), JobsFailedPlugin::make() ->label('Failed') ->pluralLabel('Failed jobs') ->navigationIcon('heroicon-o-face-frown') ->navigationGroup('Queues & Workers') ->navigationCountBadge(true), JobsBatchesPlugin::make(), ]) ``` -------------------------------- ### Cron Job for Queue Worker Source: https://context7.com/mooxphp/jobs/llms.txt Set up a cron job to run the queue worker every minute. This is useful for shared hosting environments where SSH access is limited. Ensure to redirect output to /dev/null to avoid unwanted logs. ```bash * * * * * curl -s "https://example.com/queue/work?_token=my-very-secret-token" >> /dev/null 2>&1 ``` -------------------------------- ### Default Jobs Configuration File Source: https://github.com/mooxphp/jobs/blob/main/README.md This is the content of the published configuration file. It defines resources for jobs, waiting jobs, failed jobs, and job batches, along with pruning settings. ```php return [ 'resources' => [ 'jobs' => [ 'enabled' => true, 'label' => 'Job', 'plural_label' => 'Jobs', 'navigation_group' => 'Job manager', 'navigation_icon' => 'heroicon-o-play', 'navigation_count_badge' => true, 'resource' => Moox\Jobs\Resources\JobsResource::class, ], 'jobs_waiting' => [ 'enabled' => true, 'label' => 'Job waiting', 'plural_label' => 'Jobs waiting', 'navigation_group' => 'Job manager', 'navigation_icon' => 'heroicon-o-pause', 'navigation_count_badge' => true, 'resource' => Moox\Jobs\Resources\JobsWaitingResource::class, ], 'failed_jobs' => [ 'enabled' => true, 'label' => 'Failed Job', 'plural_label' => 'Failed Jobs', 'navigation_group' => 'Job manager', 'navigation_icon' => 'heroicon-o-exclamation-triangle', 'navigation_count_badge' => true, 'resource' => Moox\Jobs\Resources\JobsFailedResource::class, ], 'job_batches' => [ 'enabled' => true, 'label' => 'Job Batch', 'plural_label' => 'Job Batches', 'navigation_group' => 'Job manager', 'navigation_icon' => 'heroicon-o-inbox-stack', 'navigation_count_badge' => true, 'resource' => Moox\Jobs\Resources\JobBatchesResource::class, ], ], 'pruning' => [ 'enabled' => true, 'retention_days' => 7, ], ]; ``` -------------------------------- ### Publish Jobs Configuration Source: https://github.com/mooxphp/jobs/blob/main/README.md Use this command to publish the configuration file for the Moox Jobs package. This allows for customization of job-related settings. ```bash php artisan vendor:publish --tag="jobs-config" ``` -------------------------------- ### Update Moox Jobs to v3 with Schema Migration Source: https://context7.com/mooxphp/jobs/llms.txt Run this command to update the database schema, publish new migrations, and migrate existing job data for correct status display. Composer update is also required. ```bash composer require moox/jobs:^3.0 composer update php artisan mooxjobs:update # Prompts: # "We make necessary updates to the database schema, OK?" → yes # "We publish the new table migrations, OK?" → yes # "Do you wish to run the migrations?" → yes # "Do you want to migrate the jobs to show a correct status?" → yes ``` -------------------------------- ### Configure Jobs Plugins in AdminPanelProvider Source: https://github.com/mooxphp/jobs/blob/main/README.md Alternatively, configure all job-related settings directly within the AdminPanelProvider instead of publishing the config file. This allows for fine-grained control over each plugin's appearance and behavior. ```php ->plugins([ \Moox\Jobs\JobsPlugin::make() ->label('Job runs') ->pluralLabel('Jobs that seems to run') ->enableNavigation(true) ->navigationIcon('heroicon-o-face-smile') ->navigationGroup('My Jobs and Queues') ->navigationSort(5) ->navigationCountBadge(true) ->enablePruning(true) ->pruningRetention(7), \Moox\Jobs\JobsWaitingPlugin::make() ->label('Job waiting') ->pluralLabel('Jobs waiting in line') ->enableNavigation(true) ->navigationIcon('heroicon-o-calendar') ->navigationGroup('My Jobs and Queues') ->navigationSort(5) ->navigationCountBadge(true) \Moox\Jobs\JobsFailedPlugin::make() ->label('Job failed') ->pluralLabel('Jobs that failed hard') ->enableNavigation(true) ->navigationIcon('heroicon-o-face-frown') ->navigationGroup('My Jobs and Queues') ->navigationSort(5) ->navigationCountBadge(true) ]) ``` -------------------------------- ### Implement Real-time Job Progress Tracking Source: https://context7.com/mooxphp/jobs/llms.txt Use the `JobProgress` trait in queued jobs to publish real-time progress (0-100) by calling `setProgress()`. This updates the `job_manager` row and is reflected in Filament's UI via auto-polling. ```php productIds); $current = 0; foreach ($this->productIds as $id) { // ... process product ... $current++; // Progress is clamped to 0–100 automatically $this->setProgress((int) round(($current / $total) * 100)); } } // Optional: override the display name shown in the Filament UI public function displayName(): string { return 'Import Products | ' . count($this->productIds) . ' items'; } } // Dispatch it: ImportProductsJob::dispatch(range(1, 500)); // Monitor at: /admin/jobs (auto-polls every 5 s) ``` -------------------------------- ### Test Moox Jobs Update Source: https://github.com/mooxphp/jobs/blob/main/README.md This script outlines the process for testing updates to Moox Jobs, including database migrations for various versions and components. ```bash composer create-project laravel/laravel moox-test cd moox-test mysqladmin -u root -p create moox-test composer require filament/filament php artisan filament:install --panels php artisan make:filament-user composer require moox/jobs:2.0.9 php artisan mooxjobs:install mkdir monorepo cd monorepo git clone https://github.com/mooxphp/moox mysql -u root -p moox-test < database/sql/jobs/v2/failed_jobs.sql mysql -u root -p moox-test < database/sql/jobs/v2/job_batches.sql mysql -u root -p moox-test < database/sql/jobs/v2/job_manager.sql mysql -u root -p moox-test < database/sql/jobs/v2/jobs.sql cd .. composer require moox/jobs:3.0 composer update php artisan mooxjobs:update ``` -------------------------------- ### Run Queue Worker via URL Source: https://github.com/mooxphp/jobs/blob/main/README.md This URL can be used to run the queue worker on shared hosting environments that have the Shared Hosting API enabled. An optional 'timeout' parameter can be added to specify the worker's timeout in seconds. ```url https://yourdomain.com/queue/work?token=secure ``` ```url https://yourdomain.com/queue/work?token=secure&timeout=300 ``` -------------------------------- ### Format Seconds Utility Source: https://context7.com/mooxphp/jobs/llms.txt Demonstrates the usage of the `formatSeconds` trait for converting a total number of seconds into a human-readable string format (e.g., '1 h 1 m 1 s'). This is used internally by the JobStatsOverview widget. ```php use Moox\Jobs\Traits\FormatSeconds; class MyWidget { use FormatSeconds; public function display(): void { echo $this->formatSeconds(90); // "1 m 30 s" echo $this->formatSeconds(3700); // "1 h 1 m 40 s" echo $this->formatSeconds(90061); // "1 d 1 h 1 m 1 s" } } ``` -------------------------------- ### Querying Job Batches Source: https://context7.com/mooxphp/jobs/llms.txt Use the JobBatch model to query entries in the native Laravel `job_batches` table. Access properties like `pending_jobs` and `failed_jobs`. ```php use Moox\Jobs\Models\JobBatch; // Get all incomplete batches $active = JobBatch::query() ->whereNull('finished_at') ->whereNull('cancelled_at') ->orderByDesc('created_at') ->get(['id', 'name', 'total_jobs', 'pending_jobs', 'failed_jobs']); // Check a specific batch $batch = JobBatch::find('550e8400-e29b-41d4-a716-446655440000'); echo $batch->pending_jobs; // jobs not yet processed echo $batch->failed_jobs; // number of failures so far echo $batch->finished_at; // null if still running ``` -------------------------------- ### Implement Bulk Retry for Failed Jobs Source: https://context7.com/mooxphp/jobs/llms.txt This code defines a BulkAction for the JobsFailedResource to retry multiple failed jobs. It iterates through selected records and calls the 'queue:retry' Artisan command for each, followed by a success notification. ```php BulkAction::make('retry') ->label('Retry') ->requiresConfirmation() ->action(function (Collection $records): void { foreach ($records as $record) { Artisan::call('queue:retry ' . $record->uuid); } Notification::make() ->title($records->count() . ' jobs pushed back to queue') ->success() ->send(); }); ``` -------------------------------- ### Count Pending Jobs Per Queue Source: https://context7.com/mooxphp/jobs/llms.txt Query the Job model to count the number of pending jobs for each queue. This provides an overview of job distribution across different queues. ```php use Moox\Jobs\Models\Job; Job::query() ->selectRaw('queue, COUNT(*) as total') ->whereNull('reserved_at') ->groupBy('queue') ->get() ->each(fn ($row) => printf("%-20s %d\n", $row->queue, $row->total)); ``` -------------------------------- ### Register Job Policies Source: https://github.com/mooxphp/jobs/blob/main/README.md This code snippet shows how to register policies for job-related models using Laravel's ServiceProvider. This is used for authorization with Filament Shield. ```php use App\Policies\JobMonitorPolicy; use Moox\Jobs\Models\FailedJob; use Moox\Jobs\Models\JobBatch; use Moox\Jobs\Models\JobMonitor; class AuthServiceProvider extends ServiceProvider { protected $policies = [ JobManager::class => JobManagerPolicy::class, FailedJob::class => FailedJobPolicy::class, JobBatch::class => JobBatchPolicy::class, ]; } ``` -------------------------------- ### Querying and Retrying Failed Jobs Source: https://context7.com/mooxphp/jobs/llms.txt Use the FailedJob model to manage entries in the native Laravel `failed_jobs` table. Supports listing and retrying failed jobs. ```php use Moox\Jobs\Models\FailedJob; // List the 10 most recent failures $failures = FailedJob::query() ->orderByDesc('failed_at') ->limit(10) ->get(['id', 'uuid', 'connection', 'queue', 'failed_at', 'exception']); // Retry a specific failed job via Artisan (mirrors the UI's "Retry" button) $job = FailedJob::find(7); \Illuminate\Support\Facades\Artisan::call('queue:retry ' . $job->uuid); // Retry all failed jobs at once foreach (FailedJob::all() as $failedJob) { Artisan::call('queue:retry ' . $failedJob->uuid); } ``` -------------------------------- ### Register Jobs Plugins in AdminPanelProvider Source: https://github.com/mooxphp/jobs/blob/main/README.md Register the Moox Jobs plugins within your Filament AdminPanelProvider. This enables the job management features in your application's UI. ```php ->plugins([ \Moox\Jobs\JobsPlugin::make(), \Moox\Jobs\JobsWaitingPlugin::make(), \Moox\Jobs\JobsFailedPlugin::make(), \Moox\Jobs\JobsBatchesPlugin::make(), ]) ``` -------------------------------- ### Querying JobManager Records Source: https://context7.com/mooxphp/jobs/llms.txt Use the JobManager model to query job execution attempts. Supports filtering by status, time, and checking job states. ```php use Moox\Jobs\Models\JobManager; // Query running jobs $running = JobManager::query() ->where('status', 'running') ->orderByDesc('started_at') ->get(); // Query failed jobs in the last 24 hours $recentFailed = JobManager::query() ->where('failed', true) ->where('finished_at', '>=' , now()->subDay()) ->get(['id', 'name', 'queue', 'exception_message', 'finished_at']); // Check status helpers on a single record $monitor = JobManager::find(42); $monitor->isFinished(); // bool — true if finished_at is set or failed $monitor->hasFailed(); // bool — true if failed === true $monitor->hasSucceeded(); // bool — true if finished and not failed // Manual pruning trigger (normally done via `php artisan model:prune`) JobManager::query() ->where('created_at', '<=', now()->subDays(7)) ->delete(); ``` -------------------------------- ### Querying Native Laravel Jobs Source: https://context7.com/mooxphp/jobs/llms.txt Use the Job model to interact with the native Laravel `jobs` table. Access computed `status` and `display_name` attributes. ```php use Moox\Jobs\Models\Job; // List all waiting jobs $waiting = Job::query() ->whereNull('reserved_at') ->orderBy('created_at') ->get(['id', 'queue', 'payload', 'attempts', 'created_at']); foreach ($waiting as $job) { echo $job->display_name; // reads payload->displayName echo $job->status; // 'waiting' or 'running' } // Bulk-delete all waiting jobs for a specific queue Job::query()->where('queue', 'emails')->delete(); ``` -------------------------------- ### Register Policies in AuthServiceProvider Source: https://context7.com/mooxphp/jobs/llms.txt Register policies for JobManager, FailedJob, and JobBatch in your AuthServiceProvider to control access to Filament navigation items. This ensures that only authorized users can view these sections. ```php // app/Providers/AuthServiceProvider.php use App\Policies\JobManagerPolicy; use App\Policies\FailedJobPolicy; use App\Policies\JobBatchPolicy; use Moox\Jobs\Models\JobManager; use Moox\Jobs\Models\FailedJob; use Moox\Jobs\Models\JobBatch; protected $policies = [ JobManager::class => JobManagerPolicy::class, FailedJob::class => FailedJobPolicy::class, JobBatch::class => JobBatchPolicy::class, ]; ``` -------------------------------- ### Upgrade Moox Jobs V2 to V3 Source: https://github.com/mooxphp/jobs/blob/main/README.md Update Moox Jobs to version 3.x. This includes running composer update and then executing the specific update command for Moox Jobs to handle database schema changes. ```bash composer update php artisan mooxjobs:update ``` -------------------------------- ### Define Failed Job Policy Source: https://github.com/mooxphp/jobs/blob/main/README.md This PHP code defines a policy for failed jobs, controlling user access. It requires the user to have the 'manage_failed_jobs' permission. ```php namespace App\Policies; use App\Models\User; use Illuminate\Auth\Access\HandlesAuthorization; class FailedJobPolicy { use HandlesAuthorization; public function viewAny(User $user): bool { return $user->can('manage_failed_jobs'); } } ``` -------------------------------- ### Trigger Queue Cycle with Curl Source: https://context7.com/mooxphp/jobs/llms.txt Use curl to trigger a single queue worker cycle. The default timeout is 60 seconds. You can override the timeout by providing a 'timeout' parameter. ```bash curl "https://example.com/queue/work?_token=my-very-secret-token" ``` ```bash curl "https://example.com/queue/work?_token=my-very-secret-token&timeout=300" ``` -------------------------------- ### Job Manager Table Schema Source: https://context7.com/mooxphp/jobs/llms.txt The schema definition for the 'job_manager' table, which stores information about queued jobs. This includes details like job ID, name, queue, connection, timestamps, status, and progress. ```php Schema::create('job_manager', function (Blueprint $table) { $table->bigIncrements('id'); $table->string('job_id'); // native queue job ID or hash of raw body $table->string('name')->nullable(); // class name or displayName() override $table->string('queue')->nullable(); $table->string('connection')->nullable(); $table->timestamp('available_at')->nullable(); $table->timestamp('started_at')->nullable(); $table->timestamp('finished_at')->nullable(); $table->boolean('failed')->nullable(); $table->integer('attempt'); $table->integer('progress')->nullable(); // 0–100, updated by JobProgress trait $table->text('exception_message')->nullable(); $table->string('status'); // 'running' | 'succeeded' | 'failed' | 'Migrated' $table->index('job_id'); $table->index('queue'); $table->index('status'); $table->timestamps(); }); ``` -------------------------------- ### Delete Waiting Jobs from a Specific Queue Source: https://context7.com/mooxphp/jobs/llms.txt Delete all jobs currently waiting in the 'low-priority' queue using the Job model. This mirrors the functionality of the bulk-delete action in the JobsWaitingResource. ```php use Moox\Jobs\Models\Job; Job::query()->where('queue', 'low-priority')->delete(); ``` -------------------------------- ### Customize JobsResource Polling Interval Source: https://context7.com/mooxphp/jobs/llms.txt Extend the JobsResource to change the table's auto-polling interval. This is useful for adjusting how frequently the job status updates. ```php namespace App\Filament\Resources; use Moox\Jobs\Resources\JobsResource as BaseJobsResource; use Filament\Tables\Table; class JobsResource extends BaseJobsResource { public static function table(Table $table): Table { $table = parent::table($table); // Change polling to every 10 seconds return $table->poll('10s'); } } ``` -------------------------------- ### Retrieving Job ID in JobManagerProvider Source: https://context7.com/mooxphp/jobs/llms.txt The JobManagerProvider automatically hooks into Laravel's queue lifecycle. Use `getJobId` to retrieve the job_manager ID from within a job. ```php use Moox\Jobs\JobManagerProvider; use Illuminate\Contracts\Queue\Job as JobContract; $jobId = JobManagerProvider::getJobId($job); // returns string|int ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.