Skip to content

MonqueTsedConfig

Defined in: tsed/src/config/types.ts:27

Configuration options for @monque/tsed.

Extends MonqueOptions with Ts.ED-specific settings for database resolution and module behavior.

@Configuration({
  monque: {
    db: mongoClient.db("myapp"),
    collectionName: "jobs",
    defaultConcurrency: 5
  }
})
export class Server {}
  • MonqueOptions
optional baseRetryInterval?: number;

Defined in: core/dist/index.d.mts:757

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

1000
MonqueOptions.baseRetryInterval

optional collectionName?: string;

Defined in: core/dist/index.d.mts:741

Name of the MongoDB collection for storing jobs.

'monque_jobs'
MonqueOptions.collectionName

optional db?: Db;

Defined in: tsed/src/config/types.ts:55

Direct MongoDB database instance.

Use when you have a pre-connected Db object available synchronously.

@Configuration({
  monque: {
    db: mongoClient.db("myapp"),
    collectionName: "jobs"
  }
})

optional dbFactory?: () => Db | Promise<Db>;

Defined in: tsed/src/config/types.ts:75

Factory function to create the database connection.

Called once during module initialization. Supports async factories for connection pooling or lazy initialization.

Db | Promise<Db>

@Configuration({
  monque: {
    dbFactory: async () => {
      const client = await MongoClient.connect(process.env.MONGO_URI!);
      return client.db("myapp");
    }
  }
})

optional dbToken?: TokenProvider<Db>;

Defined in: tsed/src/config/types.ts:104

DI token to inject the Db instance from the container.

Use when your application already has a MongoDB provider registered in the DI container.

Can also be used to inject a MongooseService or Connection.

// First, register a MongoDB provider
registerProvider({
  provide: "MONGODB_DATABASE",
  useFactory: async () => {
    const client = await MongoClient.connect(uri);
    return client.db("myapp");
  }
});

// Then reference it in config
@Configuration({
  monque: {
    dbToken: "MONGODB_DATABASE"
  }
})

optional defaultConcurrency?: number;

Defined in: core/dist/index.d.mts:786

Default number of concurrent jobs per worker.

5
MonqueOptions.defaultConcurrency

optional disableJobProcessing?: boolean;

Defined in: tsed/src/config/types.ts:146

Disable job processing on this instance.

When true, the module will initialize the database connection (allowing you to enqueue jobs via MonqueService) but will NOT register jobs or start the polling loop. Useful for “Producer-only” nodes like API servers that only enqueue jobs but don’t process them.

// API Server (Producer-only)
@Configuration({
  monque: {
    dbFactory: async () => client.db('myapp'),
    disableJobProcessing: true, // Only enqueue, don't process
  }
})
export class ApiServer {}

// Job Server (Consumer)
@Configuration({
  monque: {
    dbFactory: async () => client.db('myapp'),
    // disableJobProcessing defaults to false - processes jobs
  }
})
export class JobServer {}
false

optional enabled?: boolean;

Defined in: tsed/src/config/types.ts:38

Enable or disable the Monque module.

When disabled:

  • Jobs are not registered
  • Lifecycle hooks are no-ops
  • MonqueService throws on access
true

optional heartbeatInterval?: number;

Defined in: core/dist/index.d.mts:818

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.

With leaseDuration, each heartbeat also extends the claim’s lease. Otherwise, recovery uses lockedAt + lockTimeout, not lastHeartbeat.

30000 (30 seconds)
MonqueOptions.heartbeatInterval

optional instanceConcurrency?: number;

Defined in: core/dist/index.d.mts:872

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.
MonqueOptions.instanceConcurrency

optional jobRetention?: object;

Defined in: core/dist/index.d.mts:830

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

optional cancelled?: number;

Age in milliseconds after which cancelled jobs are deleted. Based on ‘updatedAt’. Omit to retain cancelled jobs indefinitely.

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)
MonqueOptions.jobRetention

optional leaseDuration?: number;

Defined in: core/dist/index.d.mts:801

Opt into renewable claims and periodic stale recovery, in milliseconds. Must exceed heartbeatInterval. Upgrade all schedulers sharing the collection before enabling this option. Omit to keep absolute lockTimeout behavior.

MonqueOptions.leaseDuration

optional lockTimeout?: number;

Defined in: core/dist/index.d.mts:795

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

Applies to claims without a renewable lease. This is an absolute time locked limit based on lockedAt, not a heartbeat timeout.

1800000 (30 minutes)
MonqueOptions.lockTimeout

optional maxBackoffDelay?: number;

Defined in: core/dist/index.d.mts:765

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)
MonqueOptions.maxBackoffDelay

optional maxConcurrency?: number;

Defined in: core/dist/index.d.mts:878

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

MonqueOptions.maxConcurrency

optional maxPayloadSize?: number;

Defined in: core/dist/index.d.mts:898

Maximum allowed BSON byte size for job data payloads.

When set, enqueue(), enqueueMany(), now(), and schedule() validate the payload size using BSON.calculateObjectSize() before insertion. Jobs exceeding this limit throw PayloadTooLargeError.

When undefined, no size validation occurs.

MonqueOptions.maxPayloadSize

optional maxRetries?: number;

Defined in: core/dist/index.d.mts:751

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

10
MonqueOptions.maxRetries

optional mongooseConnectionId?: string;

Defined in: tsed/src/config/types.ts:113

Connection ID of the Mongoose connection to use.

Requires the use of dbToken pointing to MongooseService.

"default"

optional pollInterval?: number;

Defined in: core/dist/index.d.mts:746

Interval in milliseconds between polling for new jobs.

1000
MonqueOptions.pollInterval

optional recoverStaleJobs?: boolean;

Defined in: core/dist/index.d.mts:825

Whether to recover stale processing jobs on startup and, with leaseDuration, after each heartbeat. Expired leases and unleased claims older than lockTimeout are reset to pending.

true
MonqueOptions.recoverStaleJobs

optional safetyPollInterval?: number;

Defined in: core/dist/index.d.mts:922

Interval in milliseconds between safety polls when change streams are active.

When change streams are connected, the scheduler uses them as the primary notification mechanism and only polls at this longer interval as a safety net to catch any missed events. When change streams are unavailable, the scheduler falls back to the standard pollInterval.

This is separate from heartbeatInterval, which updates job liveness signals.

30000 (30 seconds)
MonqueOptions.safetyPollInterval

optional schedulerInstanceId?: string;

Defined in: core/dist/index.d.mts:808

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()
MonqueOptions.schedulerInstanceId

optional shutdownTimeout?: number;

Defined in: core/dist/index.d.mts:770

Timeout in milliseconds for graceful shutdown.

30000
MonqueOptions.shutdownTimeout

optional skipIndexCreation?: boolean;

Defined in: core/dist/index.d.mts:888

Skip automatic index creation during initialization.

When true, initialize() will not create MongoDB indexes. Use this in production environments where indexes are managed externally (e.g., via migration scripts or DBA tooling). See the production checklist for the full list of required indexes.

false
MonqueOptions.skipIndexCreation

optional statsCacheTtlMs?: number;

Defined in: core/dist/index.d.mts:909

TTL in milliseconds for getQueueStats() and getQueueViewSummaries() counts.

When set to a positive value, repeated getQueueStats() calls with the same filter return cached results instead of re-executing the aggregation pipeline. Each unique filter (job name) maintains its own cache entry.

Set to 0 to disable cached snapshots. Concurrent reads still share one query.

5000
MonqueOptions.statsCacheTtlMs

optional workerConcurrency?: number;

Defined in: core/dist/index.d.mts:779

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
MonqueOptions.workerConcurrency