openjaf/cenit

View on GitHub
lib/cenit/rabbit.rb

Summary

Maintainability
F
1 wk
Test Coverage

Method process_message has a Cognitive Complexity of 90 (exceeds 5 allowed). Consider refactoring.
Open

      def process_message(message, options = {})
        unless message.is_a?(Hash)
          message =
            begin
              JSON.parse(message)
Severity: Minor
Found in lib/cenit/rabbit.rb - About 1 day 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

Method enqueue has a Cognitive Complexity of 54 (exceeds 5 allowed). Consider refactoring.
Open

      def enqueue(message, &block)
        message = message.with_indifferent_access
        task_description = message[:task_description]
        auto_retry = message[:auto_retry].presence || Setup::Task.auto_retry_enum.first
        scheduler = message.delete(:scheduler)
Severity: Minor
Found in lib/cenit/rabbit.rb - About 1 day 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

Method start_consumer has a Cognitive Complexity of 31 (exceeds 5 allowed). Consider refactoring.
Open

      def start_consumer
        if init
          new_rabbit_consumer = RabbitConsumer.create(channel: "#{connection.host}:#{connection.local_port} (#{channel.id})",
                                                      tag: channel.generate_consumer_tag(Cenit.rabbit_mq_queue))
          new_consumer = queue.subscribe(consumer_tag: new_rabbit_consumer.tag, manual_ack: true) do |delivery_info, properties, body|
Severity: Minor
Found in lib/cenit/rabbit.rb - About 4 hrs 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

Method lookup_messages has a Cognitive Complexity of 30 (exceeds 5 allowed). Consider refactoring.
Open

      def lookup_messages(opts = {})
        channel_mutex.lock
        if channel && !channel.closed?
          dispatched_ids = []
          tenant_tasks = {}
Severity: Minor
Found in lib/cenit/rabbit.rb - About 4 hrs 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

File rabbit.rb has 349 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require 'json'
require 'openssl'
require 'bunny'

module Cenit
Severity: Minor
Found in lib/cenit/rabbit.rb - About 4 hrs to fix

    Method init has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
    Open

          def init
            channel_mutex.lock
            if ENV['SKIP_RABBIT_MQ'].to_b
              puts 'RabbitMQ SKIPPED'
              false
    Severity: Minor
    Found in lib/cenit/rabbit.rb - About 3 hrs 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

    Method process_message has 74 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

          def process_message(message, options = {})
            unless message.is_a?(Hash)
              message =
                begin
                  JSON.parse(message)
    Severity: Major
    Found in lib/cenit/rabbit.rb - About 2 hrs to fix

      Method enqueue has 69 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

            def enqueue(message, &block)
              message = message.with_indifferent_access
              task_description = message[:task_description]
              auto_retry = message[:auto_retry].presence || Setup::Task.auto_retry_enum.first
              scheduler = message.delete(:scheduler)
      Severity: Major
      Found in lib/cenit/rabbit.rb - About 2 hrs to fix

        Method lookup_messages has 49 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

              def lookup_messages(opts = {})
                channel_mutex.lock
                if channel && !channel.closed?
                  dispatched_ids = []
                  tenant_tasks = {}
        Severity: Minor
        Found in lib/cenit/rabbit.rb - About 1 hr to fix

          Method start_consumer has 45 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

                def start_consumer
                  if init
                    new_rabbit_consumer = RabbitConsumer.create(channel: "#{connection.host}:#{connection.local_port} (#{channel.id})",
                                                                tag: channel.generate_consumer_tag(Cenit.rabbit_mq_queue))
                    new_consumer = queue.subscribe(consumer_tag: new_rabbit_consumer.tag, manual_ack: true) do |delivery_info, properties, body|
          Severity: Minor
          Found in lib/cenit/rabbit.rb - About 1 hr to fix

            Method detask has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
            Open

                  def detask(message)
                    report = nil
                    case task = message.delete(:task)
                    when Class
                      task_class = task
            Severity: Minor
            Found in lib/cenit/rabbit.rb - 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

            Consider simplifying this complex logical expression.
            Open

                          if scheduler || publish_at || async_message
                            if (token = message[:token])
                              TaskToken.where(token: token).delete_all
                            end
                            message[:task_id] = task.id.to_s
            Severity: Critical
            Found in lib/cenit/rabbit.rb - About 1 hr to fix

              Method init has 32 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                    def init
                      channel_mutex.lock
                      if ENV['SKIP_RABBIT_MQ'].to_b
                        puts 'RabbitMQ SKIPPED'
                        false
              Severity: Minor
              Found in lib/cenit/rabbit.rb - About 1 hr to fix

                Method detask has 27 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                      def detask(message)
                        report = nil
                        case task = message.delete(:task)
                        when Class
                          task_class = task
                Severity: Minor
                Found in lib/cenit/rabbit.rb - About 1 hr to fix

                  Avoid deeply nested control flow statements.
                  Open

                                  if (token = message[:token])
                                    TaskToken.where(token: token).delete_all
                                  end
                  Severity: Major
                  Found in lib/cenit/rabbit.rb - About 45 mins to fix

                    Avoid deeply nested control flow statements.
                    Open

                                    if delayed
                                      Setup::DelayedMessage.create(message: message, publish_at: publish_at, scheduler: scheduler)
                                    else
                                      begin
                                        channel_mutex.lock
                    Severity: Major
                    Found in lib/cenit/rabbit.rb - About 45 mins to fix

                      Avoid deeply nested control flow statements.
                      Open

                                          if task
                                            if (rabbit_consumer = options[:rabbit_consumer] || RabbitConsumer.where(tag: options[:consumer_tag]).first)
                                              rabbit_consumer.update(executor_id: tenant.id, task_id: task.id)
                                            end
                                            task.execute(execution_id: execution_id)
                      Severity: Major
                      Found in lib/cenit/rabbit.rb - About 45 mins to fix

                        Avoid deeply nested control flow statements.
                        Open

                                          if (resume_interval = task.resume_interval)
                                            message[:publish_at] = Time.now + resume_interval
                                          end
                        Severity: Major
                        Found in lib/cenit/rabbit.rb - About 45 mins to fix

                          Avoid deeply nested control flow statements.
                          Open

                                            if task
                                              task.notify(ex)
                                            else
                                              Setup::SystemNotification.create(message: "Can not execute task for message: #{message}")
                                            end
                          Severity: Major
                          Found in lib/cenit/rabbit.rb - About 45 mins to fix

                            There are no issues that match your filters.

                            Category
                            Status