Skip to content

Commit 35d5424

Browse files
committed
fix: simplify default values
1 parent 291f16e commit 35d5424

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

src/index.ts

+18-8
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,16 @@ import { calculateProcessEvery } from './utils/processEvery';
1515

1616
const log = debug('agenda');
1717

18+
const DefaultOptions = {
19+
processEvery: 5000,
20+
defaultConcurrency: 5,
21+
maxConcurrency: 20,
22+
defaultLockLimit: 0,
23+
lockLimit: 0,
24+
defaultLockLifetime: 10 * 60 * 1000,
25+
sort: { nextRunAt: 1, priority: -1 }
26+
};
27+
1828
/**
1929
* @class
2030
*/
@@ -73,20 +83,20 @@ export class Agenda extends EventEmitter {
7383
defaultLockLifetime?: number;
7484
// eslint-disable-next-line @typescript-eslint/ban-types
7585
} & (IDatabaseOptions | IMongoOptions | {}) &
76-
IDbConfig = {},
86+
IDbConfig = DefaultOptions,
7787
cb?: (error?: Error) => void
7888
) {
7989
super();
8090

8191
this.attrs = {
8292
name: config.name || '',
83-
processEvery: calculateProcessEvery(config.processEvery),
84-
defaultConcurrency: config.defaultConcurrency || 5,
85-
maxConcurrency: config.maxConcurrency || 20,
86-
defaultLockLimit: config.defaultLockLimit || 0,
87-
lockLimit: config.lockLimit || 0,
88-
defaultLockLifetime: config.defaultLockLifetime || 10 * 60 * 1000, // 10 minute default lockLifetime
89-
sort: config.sort || { nextRunAt: 1, priority: -1 }
93+
processEvery: calculateProcessEvery(config.processEvery) || DefaultOptions.processEvery,
94+
defaultConcurrency: config.defaultConcurrency || DefaultOptions.defaultConcurrency,
95+
maxConcurrency: config.maxConcurrency || DefaultOptions.maxConcurrency,
96+
defaultLockLimit: config.defaultLockLimit || DefaultOptions.defaultLockLimit,
97+
lockLimit: config.lockLimit || DefaultOptions.lockLimit,
98+
defaultLockLifetime: config.defaultLockLifetime || DefaultOptions.defaultLockLifetime, // 10 minute default lockLifetime
99+
sort: config.sort || DefaultOptions.sort
90100
};
91101

92102
this.ready = new Promise(resolve => this.once('ready', resolve));

0 commit comments

Comments
 (0)