Skip to content

MonqueOptions

Defined in: packages/core/src/scheduler/types.ts:17

Configuration options for the Monque scheduler.

const monque = new Monque(db, {
  collectionName: 'jobs',
  pollInterval: 1000,
  maxRetries: 10,
  baseRetryInterval: 1000,
  shutdownTimeout: 30000,
  workerConcurrency: 5,      // Per-worker default
  instanceConcurrency: 20,   // Global instance limit
});
optional baseRetryInterval: number;

Defined in: packages/core/src/scheduler/types.ts:41

Base interval in milliseconds for exponential backoff calculation. Actual delay = 2^failCount * baseRetryInterval

1000

optional collectionName: string;

Defined in: packages/core/src/scheduler/types.ts:22

Name of the MongoDB collection for storing jobs.

'monque_jobs'

optional defaultConcurrency: number;

Defined in: packages/core/src/scheduler/types.ts:74

Default number of concurrent jobs per worker.

5

optional heartbeatInterval: number;

Defined in: packages/core/src/scheduler/types.ts:102

Interval in milliseconds for heartbeat updates during job processing. The scheduler periodically updates lastHeartbeat for all jobs it is processing to indicate liveness for monitoring/debugging.

Note: stale recovery is based on lockedAt + lockTimeout, not lastHeartbeat.

30000 (30 seconds)

optional instanceConcurrency: number;

Defined in: packages/core/src/scheduler/types.ts:157

Maximum number of concurrent jobs processed by this instance across all registered workers.

If reached, the scheduler will stop claiming new jobs until active jobs complete. Use this to prevent a single instance from overwhelming system resources.

Note: This is an instance-level limit. Each worker still respects its own concurrency setting, but the total across all workers cannot exceed this limit.

const monque = new Monque(db, {
  instanceConcurrency: 10, // Instance processes max 10 jobs total
  workerConcurrency: 5,    // Each worker defaults to 5 concurrent jobs
});

// With 3 workers at concurrency 5, normally 15 jobs could run.
// With instanceConcurrency: 10, only 10 jobs run at any time.

optional jobRetention: object;

Defined in: packages/core/src/scheduler/types.ts:115

Configuration for automatic cleanup of completed and failed jobs. If undefined, no cleanup is performed.

optional completed: number;

Age in milliseconds after which completed jobs are deleted. Cleaned up based on ‘updatedAt’ timestamp.

optional failed: number;

Age in milliseconds after which failed jobs are deleted. Cleaned up based on ‘updatedAt’ timestamp.

optional interval: number;

Interval in milliseconds for running the cleanup job.

3600000 (1 hour)

optional lockTimeout: number;

Defined in: packages/core/src/scheduler/types.ts:84

Maximum time in milliseconds a job can be in ‘processing’ status before being considered stale and eligible for recovery.

Stale recovery uses lockedAt as the source of truth; this is an absolute “time locked” limit, not a heartbeat timeout.

1800000 (30 minutes)

optional maxBackoffDelay: number;

Defined in: packages/core/src/scheduler/types.ts:50

Maximum delay in milliseconds for exponential backoff. If calculated delay exceeds this value, it will be capped.

Defaults to 24 hours to prevent unbounded delays.

86400000 (24 hours)

optional maxConcurrency: number;

Defined in: packages/core/src/scheduler/types.ts:164

Maximum number of concurrent jobs processed by this instance across all registered workers.


optional maxRetries: number;

Defined in: packages/core/src/scheduler/types.ts:34

Maximum number of retry attempts before marking a job as permanently failed.

10

optional pollInterval: number;

Defined in: packages/core/src/scheduler/types.ts:28

Interval in milliseconds between polling for new jobs.

1000

optional recoverStaleJobs: boolean;

Defined in: packages/core/src/scheduler/types.ts:109

Whether to recover stale processing jobs on scheduler startup. When true, jobs with lockedAt older than lockTimeout will be reset to pending.

true

optional schedulerInstanceId: string;

Defined in: packages/core/src/scheduler/types.ts:92

Unique identifier for this scheduler instance. Used for atomic job claiming - each instance uses this ID to claim jobs. Defaults to a randomly generated UUID v4.

crypto.randomUUID()

optional shutdownTimeout: number;

Defined in: packages/core/src/scheduler/types.ts:56

Timeout in milliseconds for graceful shutdown.

30000

optional workerConcurrency: number;

Defined in: packages/core/src/scheduler/types.ts:66

Default number of concurrent jobs per worker.

This is the per-worker concurrency limit applied when a worker is registered without specifying its own concurrency option.

5