Open MercatoDocsSearch docsAPI reference

User guide

Scheduled Jobs

Create a schedule for work that should recur without someone starting it manually. Inspect its next planned execution and run history after saving.

Schedules can execute commands or enqueue work at a specified time or interval.

Overview

The scheduler provides:

Accessing Scheduled Jobs

Navigate to Configuration → Scheduled Jobs in the admin panel.

Scheduled Jobs List

The list shows all configured schedules with:

Creating a Schedule

Click New Schedule to create a new scheduled job.

Create Schedule Form

Basic Information

Schedule Configuration

Filled Schedule Form

Target Configuration

Enable/Disable

Toggle the Enabled switch to activate or deactivate the schedule without deleting it.

Schedule Actions

From the list view, each schedule has an actions menu:

Execution Strategies

The scheduler supports two execution strategies:

Local Strategy (Development)

Environment: QUEUE_STRATEGY=local (default)

Start the scheduler:

yarn mercato scheduler start

Keep this process running in a terminal.

Async Strategy (Production)

Environment: QUEUE_STRATEGY=async

Setup:

  1. Sync schedules with BullMQ (one-time):
yarn mercato scheduler start
  1. Start workers in separate processes:
yarn mercato queue worker --all

CLI Commands

The scheduler module provides several CLI commands:

# List all schedules
yarn mercato scheduler list [--tenant <id>] [--scope <type>] [--enabled <true|false>]

# Show scheduler status
yarn mercato scheduler status

# Manually run a schedule
yarn mercato scheduler run <schedule-id>

# Start scheduler engine
yarn mercato scheduler start

Common Use Cases

Daily Reports

Schedule a report generation job to run every morning:

Data Synchronization

Sync data with external services every 15 minutes:

Cleanup Tasks

Remove old records weekly:

Currency Rate Updates

Fetch exchange rates every 6 hours:

Access Control

The scheduler module uses these features for access control:

Users need the appropriate features assigned to their role to access scheduler functionality.

Best Practices

  1. Use descriptive names - Make it clear what each schedule does
  2. Set appropriate scopes - Use System scope only when truly global
  3. Test with intervals first - Use simple intervals during development, switch to cron for production
  4. Monitor execution history - Regularly check job runs for failures (async mode)
  5. Use timezone awareness - Always specify the correct timezone for business logic
  6. Validate JSON payloads - Ensure Job Arguments are valid JSON before saving
  7. Start with disabled schedules - Create new schedules in disabled state, test manually, then enable
  8. Document your schedules - Use the Description field to explain the purpose and impact

Troubleshooting

Schedule Not Running

Invalid Cron Expression

Command Not Found

Queue Job Not Processing

Technical Details

Database Table

Schedules are stored in the scheduled_jobs table with:

Events

The scheduler emits events for monitoring:

Feature Flags

Schedules can optionally require a feature flag:

Previous: Shipments · Next: Search the back office