CLI
Use the scheduler commands when a job needs inspection or maintenance from the terminal. Check the environment and queue configuration alongside the schedule.
List all scheduled jobs with optional filtering.
yarn mercato scheduler list [options]
Options:
| Option | Description | Example |
|---|---|---|
--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.
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
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:
| Argument | Description | Required |
|---|---|---|
schedule-id | The UUID of the schedule to run | Yes |
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:
0 - Run enqueued1 - Failed: missing or invalid schedule-id, schedule not found, QUEUE_STRATEGY is not async, the database/app container could not be initialized, or the job could not be enqueuedStart 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:
0 - Success (async: sync complete, local: clean shutdown on Ctrl+C or SIGTERM)1 - Startup failed (the database/app container could not be initialized, the scheduler service is unavailable, the local polling engine failed to start, or the BullMQ sync failed)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.
# 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.
# 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
# 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).
# 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).
The scheduler CLI respects these environment variables:
| Variable | Description | Default |
|---|---|---|
QUEUE_STRATEGY | Execution strategy: local or async | local |
QUEUE_REDIS_URL | Redis connection URL for queues and the scheduler (async mode); takes precedence over REDIS_URL | No default; set this or REDIS_URL in async mode |
REDIS_URL | Fallback Redis connection URL when QUEUE_REDIS_URL is unset | No default; required in async mode if QUEUE_REDIS_URL is unset |
SCHEDULER_POLL_INTERVAL_MS | Poll interval in milliseconds (local mode) | 30000 |
DATABASE_URL | PostgreSQL connection URL | Required |
OM_LOG_LEVEL | Logging level: debug, info, warn, error | info when NODE_ENV=production, otherwise debug |
| Code | Meaning | Context |
|---|---|---|
0 | Success | All commands |
1 | Any failure (missing or unknown arguments, not found, database/startup or enqueue failure) | All commands |
# 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
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.
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
# 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.
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.
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.
# 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
OM_LOG_LEVEL=debug when starting the scheduler or worker processscheduler run (async mode); runs of disabled schedules are skipped by the workerscheduler status to monitor schedule counts; inspect process output and queue status for execution failuresscheduler start after modifying schedules (async mode)Previous: CLI Overview Β· Next: yarn test:integration:ephemeral:start