Skip to content

Queue, Jobs & Scheduling

Bagisto uses Laravel's queue system for background processing of indexing, data import/export, and search operations. By default, the queue runs synchronously (sync driver), but production environments should use an async driver like Redis or database.

Queue Configuration

The queue driver is set in .env:

properties
QUEUE_CONNECTION=sync

For production, switch to an async driver:

properties
# Using Redis (recommended)
QUEUE_CONNECTION=redis
REDIS_HOST=127.0.0.1
REDIS_PORT=6379

# Or using the database driver
QUEUE_CONNECTION=database

When to Use Async Queues

If you have more than a few hundred products, or use Elasticsearch, switching to an async queue driver significantly improves admin panel responsiveness during product saves, imports, and catalog rule updates.

Built-in Jobs

Product Indexing Jobs

These jobs update product indices when products are created, updated, or deleted:

Job ClassPackagePurpose
UpdateCreateInventoryIndexWebkul\ProductReindexes inventory levels for given product IDs
UpdateCreatePriceIndexWebkul\ProductReindexes price data for given product IDs
ElasticSearch\UpdateCreateIndexWebkul\ProductUpdates Elasticsearch indices for products (only runs when Elasticsearch is the configured search engine)
ElasticSearch\DeleteIndexWebkul\ProductRemoves products from Elasticsearch across all channel/locale combinations

Catalog Rule Jobs

These jobs recalculate product pricing when catalog rules change:

Job ClassPackagePurpose
UpdateCreateCatalogRuleIndexWebkul\CatalogRuleReindexes a catalog rule and reprices associated products in batches of 100
DeleteCatalogRuleIndexWebkul\CatalogRuleReprices products after a catalog rule is deleted
UpdateCreateProductIndexWebkul\CatalogRuleReindexes a single product against all catalog rules

Data Transfer Jobs

The data import system uses Laravel's job batching for large imports:

Job ClassPackagePurpose
Import\ImportBatchWebkul\DataTransferProcesses a batch of import records
Import\LinkBatchWebkul\DataTransferLinks/associates imported records
Import\IndexBatchWebkul\DataTransferIndexes a batch of imported records
Import\LinkingWebkul\DataTransferFull linking pass after import
Import\IndexingWebkul\DataTransferFull indexing pass after import
Import\CompletedWebkul\DataTransferPost-import completion tasks

Other Jobs

Job ClassPackagePurpose
UpdateCreateSearchTermWebkul\MarketingCreates/updates search term records with usage counts
ProcessSitemapWebkul\SitemapGenerates XML sitemaps for products, categories, and CMS pages

Running the Queue Worker

For async queue drivers, run a worker process:

bash
# Start a queue worker
php artisan queue:work

# Process jobs from a specific queue
php artisan queue:work --queue=default

# Limit memory and timeout
php artisan queue:work --memory=256 --timeout=120

# Run once and exit (useful for cron-based processing)
php artisan queue:work --once

Production Workers

In production, use a process manager like Supervisor to keep queue workers running. See the Laravel Queue documentation for Supervisor configuration.

Scheduled Tasks

Bagisto's scheduled commands should be triggered via your server's crontab. Add the Laravel scheduler entry:

bash
* * * * * cd /path-to-your-project && php artisan schedule:run >> /dev/null 2>&1

Commands Intended for Scheduling

CommandSuggested FrequencyPurpose
invoice:cronDaily (e.g., 3:00 AM)Send overdue invoice reminders
exchange-rate:updateDaily / Weekly / MonthlyUpdate currency exchange rates
campaign:processEvery few minutesProcess and send marketing campaign emails
product:price-rule:indexDaily or on-demandReindex catalog rule pricing
indexer:indexDaily or on-demandFull product reindex (price, inventory, flat, elastic)

Example Crontab Entries

bash
# Laravel scheduler (handles all scheduled commands)
* * * * * cd /var/www/html/bagisto && php artisan schedule:run >> /dev/null 2>&1

# Or run specific commands directly:
0 3 * * * cd /var/www/html/bagisto && php artisan invoice:cron >> /dev/null 2>&1
0 4 * * * cd /var/www/html/bagisto && php artisan exchange-rate:update >> /dev/null 2>&1
*/5 * * * * cd /var/www/html/bagisto && php artisan campaign:process >> /dev/null 2>&1
0 2 * * * cd /var/www/html/bagisto && php artisan indexer:index >> /dev/null 2>&1

Dispatching Jobs in Your Package

To dispatch a job from your custom package, follow the standard Laravel pattern:

php
use Webkul\Product\Jobs\UpdateCreatePriceIndex;

// Dispatch to the queue
UpdateCreatePriceIndex::dispatch($productIds);

// Dispatch synchronously (bypasses queue)
UpdateCreatePriceIndex::dispatchSync($productIds);

When creating custom jobs, place them in your package's Jobs/ directory:

packages/Webkul/YourPackage/src/Jobs/
└── YourCustomJob.php
php
<?php

namespace Webkul\YourPackage\Jobs;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;

class YourCustomJob implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    public function __construct(
        protected array $data
    ) {}

    public function handle(): void
    {
        // Your background processing logic
    }
}

Released under the MIT License.