bbc/cloudflare-queue-consumer

View on GitHub

Showing 11 of 17 total issues

File consumer.ts has 323 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import { TypedEventEmitter } from "../utils/emitter.js";
import type {
  ConsumerOptions,
  Message,
  PullMessagesResponse,
Severity: Minor
Found in src/lib/consumer.ts - About 3 hrs to fix

    Function validateOption has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
    Open

    function validateOption(option: string, value: number, strict?: boolean): void {
      switch (option) {
        case "batchSize":
          if (value > 100 || value < 1) {
            throw new Error("batchSize must be between 1 and 100");
    Severity: Minor
    Found in src/utils/validation.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 executeHandler has 34 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      private async executeHandler(message: Message): Promise<Message> {
        let handleMessageTimeoutId: NodeJS.Timeout | undefined = undefined;
    
        try {
          let result;
    Severity: Minor
    Found in src/lib/consumer.ts - About 1 hr to fix

      Function poll has 28 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        private async poll(): Promise<void> {
          if (this.stopped) {
            logger.debug("cancelling_poll", {
              detail:
                "Poll was called while consumer was stopped, cancelling poll...",
      Severity: Minor
      Found in src/lib/consumer.ts - About 1 hr to fix

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

        function validateOption(option: string, value: number, strict?: boolean): void {
          switch (option) {
            case "batchSize":
              if (value > 100 || value < 1) {
                throw new Error("batchSize must be between 1 and 100");
        Severity: Minor
        Found in src/utils/validation.ts - About 1 hr to fix

          Function acknowledgeMessage has 26 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            private async acknowledgeMessage(
              acks: Message[],
              retries: Message[],
            ): Promise<AckMessageResponse> {
              try {
          Severity: Minor
          Found in src/lib/consumer.ts - About 1 hr to fix

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

              private async executeHandler(message: Message): Promise<Message> {
                let handleMessageTimeoutId: NodeJS.Timeout | undefined = undefined;
            
                try {
                  let result;
            Severity: Minor
            Found in src/lib/consumer.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 exponentialBackoff has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

            async function exponentialBackoff<T>(
              fn: () => Promise<T>,
              maxRetries: number,
            ): Promise<T> {
              let attempt = 0;
            Severity: Minor
            Found in src/lib/cloudflare.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 handleQueueResponse has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

              private async handleQueueResponse(
                response: PullMessagesResponse,
              ): Promise<void> {
                if (!response.success) {
                  this.emit("error", new Error("Failed to pull messages"));
            Severity: Minor
            Found in src/lib/consumer.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 processMessage has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

              private async processMessage(message: Message): Promise<void> {
                try {
                  this.emit("message_received", message);
            
                  // At the moment, we don't extend timeouts on a heartbeat
            Severity: Minor
            Found in src/lib/consumer.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 processMessageBatch has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

              private async processMessageBatch(messages: Message[]): Promise<void> {
                try {
                  messages.forEach((message: Message): void => {
                    this.emit("message_received", message);
                  });
            Severity: Minor
            Found in src/lib/consumer.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

            Severity
            Category
            Status
            Source
            Language