rschmukler/agenda

View on GitHub

Showing 81 of 81 total issues

Similar blocks of code found in 4 locations. Consider refactoring.
Open

                if (runningJobIndex === -1) {
                    // lookup by id
                    runningJobIndex = this.runningJobs.findIndex(
                        j => j.attrs._id?.toString() === job.attrs._id?.toString()
                    );
Severity: Major
Found in src/JobProcessor.ts and 3 other locations - About 1 hr to fix
src/JobProcessingQueue.ts on lines 43..48
src/JobProcessor.ts on lines 429..434
src/JobProcessor.ts on lines 604..609

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 72.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 4 locations. Consider refactoring.
Open

                        if (lockedJobIndex === -1) {
                            // lookup by id
                            lockedJobIndex = this.lockedJobs.findIndex(
                                j => j.attrs._id?.toString() === job.attrs._id?.toString()
                            );
Severity: Major
Found in src/JobProcessor.ts and 3 other locations - About 1 hr to fix
src/JobProcessingQueue.ts on lines 43..48
src/JobProcessor.ts on lines 589..594
src/JobProcessor.ts on lines 604..609

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 72.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 4 locations. Consider refactoring.
Open

                if (lockedJobIndex === -1) {
                    // lookup by id
                    lockedJobIndex = this.lockedJobs.findIndex(
                        j => j.attrs._id?.toString() === job.attrs._id?.toString()
                    );
Severity: Major
Found in src/JobProcessor.ts and 3 other locations - About 1 hr to fix
src/JobProcessingQueue.ts on lines 43..48
src/JobProcessor.ts on lines 429..434
src/JobProcessor.ts on lines 589..594

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 72.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Function getStatus has 46 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    async getStatus(fullDetails = false): Promise<IAgendaStatus> {
        const jobStatus = Object.keys(this.jobStatus).reduce((obj, key) => {
            // eslint-disable-next-line no-param-reassign
            obj[key] = {
                ...this.jobStatus[key],
Severity: Minor
Found in src/JobProcessor.ts - About 1 hr to fix

    Function jobQueueFilling has 41 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        private async jobQueueFilling(name: string): Promise<void> {
            this.isJobQueueFilling.set(name, true);
    
            try {
                // Don't lock because of a limit we have set (lockLimit, etc)
    Severity: Minor
    Found in src/JobProcessor.ts - About 1 hr to fix

      Function checkIfJobIsStillAlive has 40 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

                          new Promise<void>((resolve, reject) => {
                              setTimeout(async () => {
                                  // when job is not running anymore, just finish
                                  if (!jobIsRunning) {
                                      log.extend('runOrRetry')(
      Severity: Minor
      Found in src/JobProcessor.ts - About 1 hr 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 insert has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
        Open

            insert(job: Job): void {
                const matchIndex = this._queue.findIndex(element => {
                    if (
                        element.attrs.nextRunAt &&
                        job.attrs.nextRunAt &&
        Severity: Minor
        Found in src/JobProcessingQueue.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

        Identical blocks of code found in 6 locations. Consider refactoring.
        Open

        function getCurrentHashName() {
          var pageSubSectionId;
          var pageSubSectionHash = window.location.hash;
        
          if (pageSubSectionHash) {
        Severity: Major
        Found in docs/agenda/2.2.0/scripts/pagelocation.js and 5 other locations - About 1 hr to fix
        docs/agenda/1.0.3/scripts/pagelocation.js on lines 78..89
        docs/agenda/2.0.0/scripts/pagelocation.js on lines 78..89
        docs/agenda/3.1.0/scripts/pagelocation.js on lines 78..89
        docs/agenda/4.0.1/scripts/pagelocation.js on lines 78..89
        docs/agenda/4.2.0/scripts/pagelocation.js on lines 78..89

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 65.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Identical blocks of code found in 6 locations. Consider refactoring.
        Open

        function getCurrentHashName() {
          var pageSubSectionId;
          var pageSubSectionHash = window.location.hash;
        
          if (pageSubSectionHash) {
        Severity: Major
        Found in docs/agenda/1.0.3/scripts/pagelocation.js and 5 other locations - About 1 hr to fix
        docs/agenda/2.0.0/scripts/pagelocation.js on lines 78..89
        docs/agenda/2.2.0/scripts/pagelocation.js on lines 78..89
        docs/agenda/3.1.0/scripts/pagelocation.js on lines 78..89
        docs/agenda/4.0.1/scripts/pagelocation.js on lines 78..89
        docs/agenda/4.2.0/scripts/pagelocation.js on lines 78..89

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 65.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Identical blocks of code found in 6 locations. Consider refactoring.
        Open

        function getCurrentHashName() {
          var pageSubSectionId;
          var pageSubSectionHash = window.location.hash;
        
          if (pageSubSectionHash) {
        Severity: Major
        Found in docs/agenda/4.0.1/scripts/pagelocation.js and 5 other locations - About 1 hr to fix
        docs/agenda/1.0.3/scripts/pagelocation.js on lines 78..89
        docs/agenda/2.0.0/scripts/pagelocation.js on lines 78..89
        docs/agenda/2.2.0/scripts/pagelocation.js on lines 78..89
        docs/agenda/3.1.0/scripts/pagelocation.js on lines 78..89
        docs/agenda/4.2.0/scripts/pagelocation.js on lines 78..89

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 65.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Identical blocks of code found in 6 locations. Consider refactoring.
        Open

        function getCurrentHashName() {
          var pageSubSectionId;
          var pageSubSectionHash = window.location.hash;
        
          if (pageSubSectionHash) {
        Severity: Major
        Found in docs/agenda/4.2.0/scripts/pagelocation.js and 5 other locations - About 1 hr to fix
        docs/agenda/1.0.3/scripts/pagelocation.js on lines 78..89
        docs/agenda/2.0.0/scripts/pagelocation.js on lines 78..89
        docs/agenda/2.2.0/scripts/pagelocation.js on lines 78..89
        docs/agenda/3.1.0/scripts/pagelocation.js on lines 78..89
        docs/agenda/4.0.1/scripts/pagelocation.js on lines 78..89

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 65.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Identical blocks of code found in 6 locations. Consider refactoring.
        Open

        function getCurrentHashName() {
          var pageSubSectionId;
          var pageSubSectionHash = window.location.hash;
        
          if (pageSubSectionHash) {
        Severity: Major
        Found in docs/agenda/2.0.0/scripts/pagelocation.js and 5 other locations - About 1 hr to fix
        docs/agenda/1.0.3/scripts/pagelocation.js on lines 78..89
        docs/agenda/2.2.0/scripts/pagelocation.js on lines 78..89
        docs/agenda/3.1.0/scripts/pagelocation.js on lines 78..89
        docs/agenda/4.0.1/scripts/pagelocation.js on lines 78..89
        docs/agenda/4.2.0/scripts/pagelocation.js on lines 78..89

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 65.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Identical blocks of code found in 6 locations. Consider refactoring.
        Open

        function getCurrentHashName() {
          var pageSubSectionId;
          var pageSubSectionHash = window.location.hash;
        
          if (pageSubSectionHash) {
        Severity: Major
        Found in docs/agenda/3.1.0/scripts/pagelocation.js and 5 other locations - About 1 hr to fix
        docs/agenda/1.0.3/scripts/pagelocation.js on lines 78..89
        docs/agenda/2.0.0/scripts/pagelocation.js on lines 78..89
        docs/agenda/2.2.0/scripts/pagelocation.js on lines 78..89
        docs/agenda/4.0.1/scripts/pagelocation.js on lines 78..89
        docs/agenda/4.2.0/scripts/pagelocation.js on lines 78..89

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 65.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        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

          Similar blocks of code found in 3 locations. Consider refactoring.
          Open

                      runningJobs: !fullDetails
                          ? this.runningJobs.length
                          : this.runningJobs.map(job => ({
                                  ...job.toJson(),
                                  canceled: job.getCanceledMessage()
          Severity: Major
          Found in src/JobProcessor.ts and 2 other locations - About 1 hr to fix
          src/JobProcessor.ts on lines 62..67
          src/JobProcessor.ts on lines 68..73

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 60.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          Similar blocks of code found in 3 locations. Consider refactoring.
          Open

                      lockedJobs: !fullDetails
                          ? this.lockedJobs.length
                          : this.lockedJobs.map(job => ({
                                  ...job.toJson(),
                                  canceled: job.getCanceledMessage()
          Severity: Major
          Found in src/JobProcessor.ts and 2 other locations - About 1 hr to fix
          src/JobProcessor.ts on lines 56..61
          src/JobProcessor.ts on lines 68..73

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 60.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          Function computeFromInterval has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
          Open

          export const computeFromInterval = (attrs: IJobParameters<any>): Date => {
              const previousNextRunAt = attrs.nextRunAt || new Date();
              log('[%s:%s] computing next run via interval [%s]', attrs.name, attrs._id, attrs.repeatInterval);
          
              const lastRun = dateForTimezone(attrs.lastRunAt || new Date(), attrs.repeatTimezone);
          Severity: Minor
          Found in src/utils/nextRunAt.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

          Similar blocks of code found in 3 locations. Consider refactoring.
          Open

                      jobsToLock: !fullDetails
                          ? this.jobsToLock.length
                          : this.jobsToLock.map(job => ({
                                  ...job.toJson(),
                                  canceled: job.getCanceledMessage()
          Severity: Major
          Found in src/JobProcessor.ts and 2 other locations - About 1 hr to fix
          src/JobProcessor.ts on lines 56..61
          src/JobProcessor.ts on lines 62..67

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 60.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          Function runJob has 27 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              async runJob() {
                  const definition = this.agenda.definitions[this.attrs.name];
          
                  if (!definition) {
                      log('[%s:%s] has no definition, can not run', this.attrs.name, this.attrs._id);
          Severity: Minor
          Found in src/Job.ts - About 1 hr to fix
            Severity
            Category
            Status
            Source
            Language