Showing 26 of 26 total issues

Class App has 23 methods (exceeds 20 allowed). Consider refactoring.
Open

class App
  include Mongoid::Document
  include Peas::ModelWorker

  GIT_RECEIVER_PATH = File.expand_path "#{Peas.root}/bin/git_receiver"
Severity: Minor
Found in api/models/app.rb - About 2 hrs to fix

    Method initialize has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
    Open

      def initialize(pea)
        info "Starting to watch #{pea.full_name}'s logs for archiving"
        socket = Peas::Switchboard.connection
        socket.puts "app_logs.#{pea._id}"
    
    
    Severity: Minor
    Found in switchboard/clients/lib/pea_logs_watcher.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

    Method authenticate has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
    Open

      def authenticate
        @current_user = false
        api_key = read_line.strip
        if api_key.length >= 64
          if api_key == Setting.retrieve('peas.switchboard_key')
    Severity: Minor
    Found in switchboard/server/lib/connection.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

    Method broadcasters has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
    Open

        def broadcasters(message)
          @job_broadcasters ||= {}
          # Broadcast to parent and current. But only both if they're actually different jobs.
          #
          # There's a potential race condition if broadcasting to @current_job *before* parent_job;
    Severity: Minor
    Found in lib/worker/model_worker.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

    Method spawn_container has 34 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def spawn_container
        # Common properties
        properties = {
          'Cmd' => ['/bin/bash', '-c', command],
          # The base Docker image to use. In this case the prebuilt image created by the buildstep
    Severity: Minor
    Found in api/models/pea.rb - About 1 hr to fix

      Method command has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

          def command(command, timeout: 60)
            output = []
            @write.puts "#{command} 2>&1; echo $?; echo 'PEAS_SH_COMPLETE'"
            begin
              Timeout.timeout(timeout) do
      Severity: Minor
      Found in lib/sh.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

      Method call has 31 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def call(env)
            req = Rack::Request.new(env)
            method = req.request_method.downcase
            method[0..0] = method[0..0].upcase
      
      
      Severity: Minor
      Found in lib/proxy.rb - About 1 hr to fix

        Method initialize has 30 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          def initialize(pea)
            info "Starting to watch #{pea.full_name}'s logs for archiving"
            socket = Peas::Switchboard.connection
            socket.puts "app_logs.#{pea._id}"
        
        
        Severity: Minor
        Found in switchboard/clients/lib/pea_logs_watcher.rb - About 1 hr to fix

          Method run has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
          Open

            def run
              loop do
                # Fetch all the running docker containers on the current host
                docker_ids = Docker::Container.all.map { |c| c.id }
                docker_ids.each do |id|
          Severity: Minor
          Found in switchboard/clients/logs_archiver.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

          Method create_job has 26 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

                def create_job(method, args)
                  # UUID's are guaranteed to be practically unique, as in *extremely* unlikely to collide
                  new_job_id = SecureRandom.uuid
                  # @is_parent_caller differentiates the parent job as originally called (outside a worker process) and the parent
                  # job as run by a worker process.
          Severity: Minor
          Found in lib/worker/model_proxy.rb - About 1 hr to fix

            Method worker_manager has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
            Open

                  def worker_manager(method, *args, &block)
                    new_job_id = create_job method, args
                    # Wait for job to finish before running subsequent tasks
                    if block_given? || @block_until_complete
                      socket = Peas::Switchboard.connection
            Severity: Minor
            Found in lib/worker/model_proxy.rb - 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

            Method stream_job has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
            Open

              def self.stream_job(job)
                API.stream_output "subscribe.job_progress.#{job}" do |line|
                  if line.key? 'status'
                    if line['status'] == 'failed'
                      raise line['body']
            Severity: Minor
            Found in cli/lib/peas/api.rb - 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

            Method call has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
            Open

                def call(env)
                  req = Rack::Request.new(env)
                  method = req.request_method.downcase
                  method[0..0] = method[0..0].upcase
            
            
            Severity: Minor
            Found in lib/proxy.rb - 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

            Method request has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
            Open

              def request(verb, method, query = {}, auth = true, print = true)
                options = { query: query }
                options[:headers] = { 'x-api-key' => api_key } if auth
                request_args = [
                  verb.to_s.downcase,
            Severity: Minor
            Found in cli/lib/peas/api.rb - 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

            Method dispatch has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
            Open

              def dispatch
                _, @port, @host = @socket.peeraddr
                debug "Received connection (ID: #{@socket.object_id}) from #{@host}:#{@port}"
            
                return unless authenticate
            Severity: Minor
            Found in switchboard/server/lib/connection.rb - 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

            Method spawn_container has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
            Open

              def spawn_container
                # Common properties
                properties = {
                  'Cmd' => ['/bin/bash', '-c', command],
                  # The base Docker image to use. In this case the prebuilt image created by the buildstep
            Severity: Minor
            Found in api/models/pea.rb - 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

            Method broadcast has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
            Open

                def broadcast(message = {})
                  raise 'broadcast() can only be used if method is part of a running job.' unless @current_job
                  message = message.to_s unless message.is_a?(Hash)
                  if message.is_a? String
                    tmp_msg = message
            Severity: Minor
            Found in lib/worker/model_worker.rb - 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

            Method api_domain has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
            Open

              def self.api_domain
                git_domain = Git.sh 'git config peas.domain'
                domain =
                if ENV['PEAS_API_ENDPOINT']
                  ENV['PEAS_API_ENDPOINT']
            Severity: Minor
            Found in cli/lib/peas/config.rb - 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

            Method handle_status has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
            Open

                  def handle_status(method, status, progress, &_block)
                    if status == 'failed'
                      if @is_parent_caller
                        # Only raise an error in the parent worker that started off the whole process
                        error_message = "Worker for #{@instance.class.name}.#{method} failed. Job aborted. " + progress['body']
            Severity: Minor
            Found in lib/worker/model_proxy.rb - 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

            Method request has 5 arguments (exceeds 4 allowed). Consider refactoring.
            Open

              def request(verb, method, query = {}, auth = true, print = true)
            Severity: Minor
            Found in cli/lib/peas/api.rb - About 35 mins to fix
              Severity
              Category
              Status
              Source
              Language