Open MercatoDocsSearch docsAPI reference

CLI

Scheduler CLI

Use the scheduler commands when a job needs inspection or maintenance from the terminal. Check the environment and queue configuration alongside the schedule.

Available Commands

scheduler list

List all scheduled jobs with optional filtering.

yarn mercato scheduler list [options]

Options:

OptionDescriptionExample
--tenant <id>Filter by tenant ID (alias: --tenantId)--tenant 123e4567-e89b-12d3-a456-426614174000
--scope <type>Filter by scope type (alias: --scopeType)--scope system
--enabled <bool>Filter by enabled status--enabled true

Examples:

# List all schedules
yarn mercato scheduler list

# List only system-scoped schedules
yarn mercato scheduler list --scope system

# List enabled schedules for a tenant
yarn mercato scheduler list --tenant 123e4567-e89b-12d3-a456-426614174000 --enabled true

Example output (illustrative schedules; the mercato CLI wrapper can log additional lines):


Found 2 scheduled job(s):

ID                                    Name                               Type        Schedule            Status    Next Run
--------------------------------------------------------------------------------------------------------------------------------------------
123e4567-e89b-12d3-a456-426614174000  Fetch Currency Rates               cron        0 */6 * * *         βœ“ Enabled 2026-11-05T12:00:00.000Z
123e4567-e89b-12d3-a456-426614174001  Daily Sales Report                 cron        0 6 * * *           βœ— DisabledN/A

When no schedules match, the command prints No scheduled jobs found.


scheduler status

Show the current status of the scheduler system.

yarn mercato scheduler status

The samples below use illustrative counts and the default local poll interval. They show the lines scheduler status prints; the mercato CLI wrapper can log additional lines. The command reports schedule counts from the database, rather than checking scheduler or worker process health or Redis connectivity.

Output (Local Strategy):


πŸ“Š Scheduler Status

Strategy: Local (polling)
Poll Interval: 30s

Schedules:
  Total: 5
  Enabled: 4
  Due Now: 1

Output (Async Strategy):


πŸ“Š Scheduler Status

Strategy: BullMQ (async)

Schedules:
  Total: 5
  Enabled: 4
  Due Now: 1


scheduler run

Manually execute a scheduled job immediately.

yarn mercato scheduler run <schedule-id>

Note

Like POST /api/scheduler/trigger, this command requires QUEUE_STRATEGY=async: it enqueues the run on the scheduler-execution queue for a worker to execute. With the local strategy it exits with an error, because the local scheduler runs due schedules by polling and never consumes that queue.

Arguments:

ArgumentDescriptionRequired
schedule-idThe UUID of the schedule to runYes

Example:

yarn mercato scheduler run 123e4567-e89b-12d3-a456-426614174000

The command only enqueues the run; a scheduler-execution worker executes it later. It does not wait for the result. A disabled schedule is still enqueued (and the command still reports success), but the worker skips it and emits scheduler.job.skipped.

The sample shows the lines scheduler run prints. The mercato CLI wrapper logs additional lines around them.

Output (Success):

πŸš€ Manually triggering schedule: Fetch Currency Rates

  ID: 123e4567-e89b-12d3-a456-426614174000
  Type: cron
  Schedule: 0 */6 * * *
  Target: currency-rates

βœ“ Job successfully triggered via scheduler-execution queue (job 42)
  The worker will pick it up and enqueue to: currency-rates
βœ“ Manual trigger completed

While the run is waiting or running, and if it fails, it appears in the schedule's execution history at GET /api/scheduler/jobs/{id}/executions. Completed jobs are removed from the queue, so a successful run does not stay in that history.

Exit Codes:


scheduler start

Start the scheduler engine.

Tip

Behavior differs based on QUEUE_STRATEGY:

yarn mercato scheduler start

The samples below show the lines the scheduler start command prints. The mercato CLI wrapper and the scheduler services can log additional lines around them.

Local Strategy Output:

πŸš€ Starting scheduler (strategy: local)...

βœ“ Local scheduler started (polling every 30 seconds)
Press Ctrl+C to stop.

πŸ’‘ Tip: For production, use QUEUE_STRATEGY=async with Redis.

On Ctrl+C (or SIGTERM) the local scheduler stops and prints:

πŸ“› Shutting down...
βœ“ Stopped

Async Strategy Output:

πŸš€ Starting scheduler (strategy: async)...

βœ“ Scheduler sync completed

BullMQ is managing all schedules.
Start workers to process jobs:
  yarn mercato queue worker --all

Options:

scheduler start takes no command-line options. Set the local poll interval with the SCHEDULER_POLL_INTERVAL_MS environment variable (default 30000):

# Start with default settings
yarn mercato scheduler start

# Start with a custom poll interval (local mode)
SCHEDULER_POLL_INTERVAL_MS=60000 yarn mercato scheduler start

Exit Codes:


scheduler audit-queue-targets

Audit persisted module-authored schedules that target queues, optionally filtering by tenant:

yarn mercato scheduler audit-queue-targets
yarn mercato scheduler audit-queue-targets --tenant 123e4567-e89b-12d3-a456-426614174000

--tenantId is also accepted. The command prints the number of module-authored queue-target schedules, then each schedule's ID, name (when present), source module, target queue, enabled status, and dispatch verdict (ALLOWED or blocked). It does not modify schedules.

When any rows are ALLOWED, the output asks you to review them against your known module integrations and disable unrecognized schedules. Pre-upgrade rows created with a non-user-bound API key cannot be distinguished from genuine registrations at rest.


Common Workflows

Development Setup

# 1. Check scheduler status
yarn mercato scheduler status

# 2. List existing schedules
yarn mercato scheduler list

# 3. Start scheduler (keeps running, runs due schedules by polling)
yarn mercato scheduler start

scheduler run needs QUEUE_STRATEGY=async, so it is not available with the local strategy used here.

Production Setup

# 1. Ensure environment is configured
export QUEUE_STRATEGY=async
export REDIS_URL=redis://localhost:6379

# 2. Check status
yarn mercato scheduler status

# 3. Sync schedules (one-time)
yarn mercato scheduler start

# 4. Start workers (separate process)
yarn mercato queue worker --all

# 5. Monitor execution
yarn mercato queue status scheduler-execution

Debugging Failed Schedules

# 1. List all schedules
yarn mercato scheduler list

# 2. Check status
yarn mercato scheduler status

# 3. Trigger the schedule manually (async mode), then check its executions
yarn mercato scheduler run <schedule-id>

# 4. Read the scheduler and worker process output (see below)

# 5. Check queue job counts, including failed jobs (async mode)
yarn mercato queue status scheduler-execution

Read the terminal output or your process supervisor's captured stdout/stderr for the scheduler and worker processes. The platform does not create logs/scheduler.log or logs/worker.log. Set OM_LOG_LEVEL=debug when starting the process to include debug logs, for example:

OM_LOG_LEVEL=debug yarn mercato queue worker scheduler-execution

To see why a specific schedule failed, read its execution history with GET /api/scheduler/jobs/{id}/executions (async mode).

Monitoring Production

# Check scheduler strategy and schedule counts
yarn mercato scheduler status

# View active schedules
yarn mercato scheduler list --enabled true

# Check waiting, active, completed and failed job counts (async mode)
yarn mercato queue status scheduler-execution

Per-schedule execution history is available through GET /api/scheduler/jobs/{id}/executions (async mode).

Environment Variables

The scheduler CLI respects these environment variables:

VariableDescriptionDefault
QUEUE_STRATEGYExecution strategy: local or asynclocal
QUEUE_REDIS_URLRedis connection URL for queues and the scheduler (async mode); takes precedence over REDIS_URLNo default; set this or REDIS_URL in async mode
REDIS_URLFallback Redis connection URL when QUEUE_REDIS_URL is unsetNo default; required in async mode if QUEUE_REDIS_URL is unset
SCHEDULER_POLL_INTERVAL_MSPoll interval in milliseconds (local mode)30000
DATABASE_URLPostgreSQL connection URLRequired
OM_LOG_LEVELLogging level: debug, info, warn, errorinfo when NODE_ENV=production, otherwise debug

Exit Codes Reference

CodeMeaningContext
0SuccessAll commands
1Any failure (missing or unknown arguments, not found, database/startup or enqueue failure)All commands

Integration with Other CLI Tools

Worker Management

# Start all workers (includes scheduler execution worker)
yarn mercato queue worker --all

# Start only scheduler worker
yarn mercato queue worker scheduler-execution

# Check scheduler queue status
yarn mercato queue status scheduler-execution

Queue Management

The queue CLI provides worker, status and clear:

# Show waiting, active, completed and failed job counts
yarn mercato queue status scheduler-execution

# Remove all jobs from the scheduler execution queue
yarn mercato queue clear scheduler-execution

There is no CLI command to list or retry individual jobs. Inspect a single job with GET /api/scheduler/queue-jobs/{jobId}?queue=scheduler-execution (async mode); take jobId from the queueJobId field of the executions endpoint, or from the (job …) id that scheduler run prints.

Database Management

Avoid passing $DATABASE_URL straight to psql – the shell expands it into the command's process arguments, which other local processes (for example ps) can read, including the password. Define the scheduler_db service in ~/.pg_service.conf (or the file selected by PGSERVICEFILE), using the non-secret connection parameters from DATABASE_URL:

[scheduler_db]
host=db.example.com
port=5432
dbname=mercato
user=scheduler_reader

Replace these example values with your deployment's host, port, database and user, and carry over its required sslmode and other TLS options. Store the password separately in ~/.pgpass (or the file selected by PGPASSFILE), with matching connection parameters:

db.example.com:5432:mercato:scheduler_reader:<database-password>

Replace <database-password> with the actual password; escape any : or \ in passfile values with \. On Unix, run chmod 600 ~/.pgpass so libpq accepts the password file. The passfile supplies a matching password; it does not define a service or select a host/database/user. The service definition above is required by both service=scheduler_db examples below. See PostgreSQL's service-file and password-file formats.

Connect by service name:

# View scheduler tables (password is read from ~/.pgpass, never from argv)
psql "service=scheduler_db" -c "\d scheduled_jobs"

# Run migrations
yarn mercato db migrate

# Generate new migration (after entity changes)
yarn mercato db generate

Troubleshooting

"Schedule not found"

# List all schedules to verify ID
yarn mercato scheduler list

# Check if schedule was soft-deleted (password is read from ~/.pgpass, never from argv)
psql "service=scheduler_db" -c "SELECT id, name, deleted_at FROM scheduled_jobs WHERE id = '123e4567-e89b-12d3-a456-426614174000' AND deleted_at IS NOT NULL;"

Replace the example UUID with the schedule ID you are investigating. Database inspection requires psql and the scheduler_db service definition and matching password-file entry described above, configured from DATABASE_URL.

Local scheduler locking

The local scheduler is intended for a single instance. It prevents overlapping runs of the same key within that process. A PostgreSQL transaction-scoped advisory lock (pg_try_advisory_xact_lock) guards the short claim transaction and is released automatically when that transaction commits or rolls back, before the job executes. There is no session lock to release manually.

Run one local scheduler process; use the async strategy with Redis for multiple workers. If the process logs Failed to acquire lock, inspect its accompanying database error in the process output.

"Redis connection failed"

QUEUE_REDIS_URL (falling back to REDIS_URL) may carry a password; expanding that URL into redis-cli -u puts the password in process arguments the same way. Set local shell variables redis_host, redis_port, redis_username and redis_password from whichever URL is selected, decoding any percent-encoded username/password. Leave redis_username empty when the URL has no username. Pass the password through REDISCLI_AUTH (or omit it and use --askpass for an interactive prompt) instead of -u:

redis_args=(-h "$redis_host" -p "${redis_port:-6379}")
if [ -n "${redis_username:-}" ]; then
  redis_args+=(--user "$redis_username")
fi
REDISCLI_AUTH="$redis_password" redis-cli "${redis_args[@]}" ping

The optional --user preserves named ACL users, including deployments with the default user disabled. If the selected URL uses rediss://, add --tls and the deployment's required certificate options to redis_args before connecting. If its path selects a database, also add -n with that database number. See the Redis CLI connection and authentication options.

"No workers running"

# Check scheduler queue status
yarn mercato queue status scheduler-execution

# Start workers
yarn mercato queue worker --all

# Read the worker process output in its terminal or process supervisor

Best Practices

  1. Use scripts for automation - Add scheduler commands to package.json scripts
  2. Monitor in production - Set up cron jobs to check scheduler status
  3. Include debug logs - Set OM_LOG_LEVEL=debug when starting the scheduler or worker process
  4. Test manually first - Enable the schedule, then trigger it once with scheduler run (async mode); runs of disabled schedules are skipped by the worker
  5. Graceful shutdowns - Always use Ctrl+C instead of kill -9
  6. Check status regularly - Run scheduler status to monitor schedule counts; inspect process output and queue status for execution failures
  7. Filter list output - Use filters to reduce noise in large deployments
  8. Sync after changes - Re-run scheduler start after modifying schedules (async mode)

See Also

Previous: CLI Overview Β· Next: yarn test:integration:ephemeral:start