RocketChat/Rocket.Chat

View on GitHub
packages/agenda/src/Agenda.ts

Summary

Maintainability
F
3 days
Test Coverage

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';
Severity: Major
Found in packages/agenda/src/Agenda.ts - About 1 day to fix

    Agenda has 46 functions (exceeds 20 allowed). Consider refactoring.
    Open

    export class Agenda extends EventEmitter {
        private _name: string | undefined;
    
        private _processEvery: number;
    
    
    Severity: Minor
    Found in packages/agenda/src/Agenda.ts - About 6 hrs to fix

      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);
      
      
      Severity: Minor
      Found in packages/agenda/src/Agenda.ts - About 1 hr to fix

        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;
        Severity: Minor
        Found in packages/agenda/src/Agenda.ts - About 1 hr to fix

          Function _runOrRetry has 29 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              private async _runOrRetry(): Promise<void> {
                  if (!this._processInterval) {
                      return;
                  }
          
          
          Severity: Minor
          Found in packages/agenda/src/Agenda.ts - About 1 hr to fix

            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;
            Severity: Minor
            Found in packages/agenda/src/Agenda.ts - About 1 hr to fix

              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) {
              Severity: Minor
              Found in packages/agenda/src/Agenda.ts - About 45 mins to fix

              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);
              
              
              Severity: Minor
              Found in packages/agenda/src/Agenda.ts - About 45 mins to fix

              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
              Severity: Minor
              Found in packages/agenda/src/Agenda.ts - About 35 mins to fix

              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;
                      }
              
              
              Severity: Minor
              Found in packages/agenda/src/Agenda.ts - About 35 mins to fix

              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;
              Severity: Minor
              Found in packages/agenda/src/Agenda.ts - About 25 mins to fix

              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;
              Severity: Minor
              Found in packages/agenda/src/Agenda.ts - About 25 mins to fix

              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

              There are no issues that match your filters.

              Category
              Status