Skip to content

Queue Management

This guide explains how to manage import/export jobs using terminal commands and cron scheduling.

Running Jobs via Terminal

Processing Single Jobs

To run a specific import or export job:

bash
# Format: php artisan unopim:queue:work <job_id> <user_email> [options]
php artisan unopim:queue:work 1 admin@example.com

# With additional options
php artisan unopim:queue:work 1 admin@example.com --queue=custom-queue --timeout=120 --tries=3

Required parameters:

  • job_id: ID of the import/export job (required)
  • user_email: The email of the unopim user executing the job (required)

Optional parameters:

  • --queue: Specify custom queue name
  • --name: Worker name (default: 'single')
  • --memory: Memory limit in MB (default: 128)
  • --timeout: Job timeout in seconds (default: 60)
  • --tries: Number of retry attempts (default: 1)

Important

Both job_id and user_email are required parameters. The command will fail if either is missing or invalid.

Managing Queue Workers

Basic queue management commands:

bash
# Start the queue worker
php artisan queue:work --queue="default,system,completeness"

# Restart queue workers (after code changes)
php artisan queue:restart

# Stop running queue workers
php artisan queue:stop

Scheduling Jobs with Cron

Basic Setup

  1. Configure your crontab:
bash
crontab -e
  1. Add the UnoPim scheduler:
bash
* * * * * cd /path/to/unopim && php artisan schedule:run >> /var/log/unopim/scheduler.log 2>&1

Scheduling a Single Job

To schedule a specific import/export job, add a cron entry that runs the unopim:queue:work command directly:

  • Assuming the job ID is 1 and the user email is admin@example.com (replace with your values), schedule it to run every hour.
bash
0 * * * * cd /path/to/unopim && php artisan unopim:queue:work 1 admin@example.com >> /var/log/unopim/job-1.log 2>&1

Important Notes

  1. Always provide valid job ID and user email
  2. User must exist in the system
  3. Queue workers cache code, restart after changes:
bash
php artisan queue:restart

Completeness Queue

Product completeness calculations are processed through a dedicated completeness queue. This ensures that completeness score recalculations do not block default or system queue workers, especially during bulk product updates.

When starting your queue worker, include the completeness queue alongside the default queues:

bash
php artisan queue:work --queue="default,system,completeness"

If you are using Supervisor, update your configuration to include the completeness queue in the --queue argument (see Configuring Supervisor).

Completeness Recalculation Commands

You can manually trigger completeness recalculation using the following commands:

bash
# Recalculate completeness for all products
php artisan unopim:completeness:recalculate --all

# Recalculate completeness for a specific attribute family
php artisan unopim:completeness:recalculate --family=ID

# Recalculate completeness for a single product
php artisan unopim:completeness:recalculate --product=ID

# Recalculate completeness for specific product IDs
php artisan unopim:completeness:recalculate --products=1 --products=2
OptionDescription
--allRecalculate completeness for all products
--family=IDRecalculate for all products in a specific attribute family
--product=IDRecalculate for a single product by ID
--products=IDRecalculate for multiple specific product IDs (repeat the option for each ID)

TIP

The --all option dispatches completeness jobs to the completeness queue, so ensure your queue worker is running with the completeness queue included.

Dashboard Cache

To clear the dashboard statistics cache so the next page load shows fresh data, run:

bash
php artisan unopim:dashboard:refresh

This is useful when dashboard statistics appear stale or after bulk data operations.


Scheduled Tasks (Automatic via Cron)

When the Laravel scheduler is configured (see Scheduling Jobs with Cron), the following tasks run automatically:

TaskScheduleDescription
unopim:product:indexDaily at 00:01 & 12:01Elasticsearch product re-indexing
unopim:category:indexDaily at 00:01 & 12:01Elasticsearch category re-indexing
unopim:completeness:recalculate --allDaily at 02:00Recalculate product completeness scores
unopim:dashboard:refreshEvery 10 minutesRefresh dashboard statistics cache

TIP

These tasks require the cron entry for php artisan schedule:run to be active. See Basic Setup above.


Notifications

Completeness Notifications

When a bulk completeness calculation finishes, all admin users with full permissions are notified via:

  1. UI notification — appears in the notification bell in the admin panel.
  2. Email notification — sent if SMTP mail is configured in your .env file.

Environment Variables

VariableDefaultDescription
NOTIFICATIONS_ENABLEDtrueEnable or disable all notifications
COMPLETENESS_QUEUEsystemQueue name for completeness jobs

Pause, Resume, and Cancel Controls

Import and export jobs support pause, resume, and cancel controls. These controls are available both in the admin UI and through the job management commands, allowing administrators to:

  • Pause a running import or export job to temporarily halt processing without losing progress.
  • Resume a paused job to continue from where it left off.
  • Cancel a job to stop it entirely and release queue resources.

Released under the MIT License.