rschmukler/agenda

View on GitHub
src/JobDbRepository.ts

Summary

Maintainability
C
1 day
Test Coverage

Function saveJob has 84 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    async saveJob<DATA = unknown | void>(job: Job<DATA>): Promise<Job<DATA>> {
        try {
            log('attempting to save a job');

            // Grab information needed to save job but that we don't want to persist in MongoDB
Severity: Major
Found in src/JobDbRepository.ts - About 3 hrs to fix

    File JobDbRepository.ts has 297 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    import * as debug from 'debug';
    import {
        Collection,
        Db,
        Filter,
    Severity: Minor
    Found in src/JobDbRepository.ts - About 3 hrs to fix

      Function saveJob has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
      Open

          async saveJob<DATA = unknown | void>(job: Job<DATA>): Promise<Job<DATA>> {
              try {
                  log('attempting to save a job');
      
                  // Grab information needed to save job but that we don't want to persist in MongoDB
      Severity: Minor
      Found in src/JobDbRepository.ts - About 1 hr 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 connect has 34 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          async connect(): Promise<void> {
              const db = await this.createConnection();
              log('successful connection to MongoDB', db.options);
      
              const collection = this.connectOptions.db?.collection || 'agendaJobs';
      Severity: Minor
      Found in src/JobDbRepository.ts - About 1 hr to fix

        Function saveJobState has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

            async saveJobState(job: Job<any>): Promise<void> {
                const id = job.attrs._id;
                const $set = {
                    lockedAt: (job.attrs.lockedAt && new Date(job.attrs.lockedAt)) || undefined,
                    nextRunAt: (job.attrs.nextRunAt && new Date(job.attrs.nextRunAt)) || undefined,
        Severity: Minor
        Found in src/JobDbRepository.ts - About 55 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 connect has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

            async connect(): Promise<void> {
                const db = await this.createConnection();
                log('successful connection to MongoDB', db.options);
        
                const collection = this.connectOptions.db?.collection || 'agendaJobs';
        Severity: Minor
        Found in src/JobDbRepository.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