Connection
The MongoDB connection can be configured through the PulseConfig
object, which supports either direct client reuse or new connection parameters.
Example Usage
new Pulse(config?, cb?)
new Pulse(config?, cb?)
Parameters
config
name
(string
- optional): Specifies the name of the job queue. This can be used for identifying and managing different queues within the same application.processEvery
(string
- optional): Defines how often the job processor should poll for new jobs to process. The string should be a human-readable interval, such as'5 minutes'
,'1 hour'
. Defaults to'5 seconds'
if not specified.maxConcurrency
(number
- optional): The maximum number of jobs that can be processed concurrently. Helps in controlling resource utilization. Defaults to'20'
if not specified.defaultConcurrency
(number
- optional): The default concurrency for jobs that do not specify their own concurrency setting. Defaults to'5'
if not specified.lockLimit
(number
- optional): Maximum number of jobs that can be locked at the same time. This prevents a single worker from locking too many jobs. Defaults to'0'
if not specified.defaultLockLimit
(number
- optional): Default limit for the number of jobs each worker can lock simultaneously. Defaults to'0'
if not specified.defaultLockLifetime
(number
- optional): Duration in milliseconds for how long a job can be locked before it is automatically unlocked. Useful for handling job crashes or stalls. Defaults to 600000 ms (10 minutes). Defaults to'10 minutes'
if not specified.sort
(any
- optional): Determines the order in which jobs are selected and locked from the database. For example,{ nextRunAt: 1, priority: -1 }
sorts bynextRunAt
ascending andpriority
descending.mongo
(MongoDb
- optional): An existing MongoDB client that can be reused instead of creating a new connection.db
(object
- optional): Configuration for the MongoDB connection if not using an existingMongoDb
client. Includes:address
(string
): The MongoDB connection URI.collection
(string
- optional): Specifies the MongoDB collection to use. Defaults topulseJobs
.options
(MongoClientOptions
- optional): MongoDB client options.
disableAutoIndex
(boolean
- optional): If set totrue
, automatic indexing of job fields by thePulse
system is disabled. Useful for performance tuning in production environments. Defaults tofalse
if not specified.resumeOnRestart
(boolean
- optional) - This config is used to ensure that jobs left unfinished due to an unexpected system shutdown or restart are properly resumed once the system is back online. Defaults totrue
if not specified.
Last updated