File Agenda.ts
has 680 lines of code (exceeds 250 allowed). Consider refactoring. Open
import { EventEmitter } from 'events';
import debugInitializer from 'debug';
import humanInterval from 'human-interval';
import { MongoClient } from 'mongodb';
Agenda
has 46 functions (exceeds 20 allowed). Consider refactoring. Open
export class Agenda extends EventEmitter {
private _name: string | undefined;
private _processEvery: number;
Function _findAndLockNextJob
has 44 lines of code (exceeds 25 allowed). Consider refactoring. Open
private async _findAndLockNextJob(jobName: string, definition: JobDefinition): Promise<Job | undefined> {
const now = new Date();
const lockDeadline = new Date(Date.now().valueOf() - definition.lockLifetime);
debug('_findAndLockNextJob(%s, [Function])', jobName);
Function _lockOnTheFly
has 39 lines of code (exceeds 25 allowed). Consider refactoring. Open
private async _lockOnTheFly(): Promise<void> {
// Already running this? Return
if (this._isLockingOnTheFly) {
debug('lockOnTheFly() already running, returning');
return;
Function _runOrRetry
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
private async _runOrRetry(): Promise<void> {
if (!this._processInterval) {
return;
}
Function _saveSingleJob
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
private async _saveSingleJob(job: Job, props: Record<string, any>, now: Date): Promise<void> {
// Job type set to 'single' so...
debug('job with type of "single" found');
const { nextRunAt, ...$set } = props;
Function processJobs
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
public processJobs(extraJob?: Job): void {
debug('starting to process jobs');
// Make sure an interval has actually been set
// Prevents race condition with 'Agenda.stop' and already scheduled run
if (!this._processInterval) {
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function _findAndLockNextJob
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
private async _findAndLockNextJob(jobName: string, definition: JobDefinition): Promise<Job | undefined> {
const now = new Date();
const lockDeadline = new Date(Date.now().valueOf() - definition.lockLifetime);
debug('_findAndLockNextJob(%s, [Function])', jobName);
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function _processDbResult
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
private async _processDbResult(job: Job, result: ModifyResult | InsertOneResult): Promise<void> {
debug('processDbResult() called with success, checking whether to process job immediately or not');
// We have a result from the above calls
// findOneAndUpdate() returns different results than insertOne() so check for that
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function _runOrRetry
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
private async _runOrRetry(): Promise<void> {
if (!this._processInterval) {
return;
}
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function constructor
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
constructor(config: AgendaConfig = {}) {
super();
this._name = config.name;
this._processEvery = humanInterval(config.processEvery) || defaultInterval;
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function _lockOnTheFly
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
private async _lockOnTheFly(): Promise<void> {
// Already running this? Return
if (this._isLockingOnTheFly) {
debug('lockOnTheFly() already running, returning');
return;
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"