mperham/sidekiq

View on GitHub

Showing 53 of 53 total issues

File api.rb has 644 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require "sidekiq"

module Sidekiq
  module RedisScanner
    def sscan(conn, key)
Severity: Major
Found in lib/sidekiq/api.rb - About 1 day to fix

    Method sidekiq_class_attribute has a Cognitive Complexity of 43 (exceeds 5 allowed). Consider refactoring.
    Open

            def sidekiq_class_attribute(*attrs)
              instance_reader = true
              instance_writer = true
    
              attrs.each do |name|
    Severity: Minor
    Found in lib/sidekiq/worker.rb - About 6 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

    Class Web has 25 methods (exceeds 20 allowed). Consider refactoring.
    Open

      class Web
        ROOT = File.expand_path("#{File.dirname(__FILE__)}/../../web")
        VIEWS = "#{ROOT}/views"
        LOCALES = ["#{ROOT}/locales"]
        LAYOUT = "#{VIEWS}/layout.erb"
    Severity: Minor
    Found in lib/sidekiq/web.rb - About 2 hrs to fix

      File cli.rb has 278 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      $stdout.sync = true
      
      require "yaml"
      require "singleton"
      require "optparse"
      Severity: Minor
      Found in lib/sidekiq/cli.rb - About 2 hrs to fix

        File application.rb has 272 lines of code (exceeds 250 allowed). Consider refactoring.
        Open

        module Sidekiq
          class WebApplication
            extend WebRouter
        
            CONTENT_LENGTH = "Content-Length"
        Severity: Minor
        Found in lib/sidekiq/web/application.rb - About 2 hrs to fix

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

            class CLI
              include Util
              include Singleton unless $TESTING
          
              attr_accessor :launcher
          Severity: Minor
          Found in lib/sidekiq/cli.rb - About 2 hrs to fix

            Method setup_options has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
            Open

                def setup_options(args)
                  # parse CLI options
                  opts = parse_options(args)
            
                  set_environment opts[:environment]
            Severity: Minor
            Found in lib/sidekiq/cli.rb - About 2 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 sidekiq_class_attribute has 54 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                    def sidekiq_class_attribute(*attrs)
                      instance_reader = true
                      instance_writer = true
            
                      attrs.each do |name|
            Severity: Major
            Found in lib/sidekiq/worker.rb - About 2 hrs to fix

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

                  def fetch_stats!
                    pipe1_res = Sidekiq.redis { |conn|
                      conn.pipelined do
                        conn.get("stat:processed")
                        conn.get("stat:failed")
              Severity: Minor
              Found in lib/sidekiq/api.rb - About 1 hr to fix

                Method parse_options has 48 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    def parse_options(argv)
                      opts = {}
                
                      @parser = OptionParser.new { |o|
                        o.on "-c", "--concurrency INT", "processor threads to use" do |arg|
                Severity: Minor
                Found in lib/sidekiq/cli.rb - About 1 hr to fix

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

                  module Sidekiq
                    module Extensions
                      ##
                      # Adds 'delay', 'delay_for' and `delay_until` methods to all Classes to offload class method
                      # execution to Sidekiq.  Examples:
                  Severity: Major
                  Found in lib/sidekiq/extensions/class_methods.rb and 1 other location - About 1 hr to fix
                  lib/sidekiq/extensions/active_record.rb on lines 5..40

                  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 73.

                  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 2 locations. Consider refactoring.
                  Open

                  module Sidekiq
                    module Extensions
                      ##
                      # Adds 'delay', 'delay_for' and `delay_until` methods to ActiveRecord to offload instance method
                      # execution to Sidekiq.  Examples:
                  Severity: Major
                  Found in lib/sidekiq/extensions/active_record.rb and 1 other location - About 1 hr to fix
                  lib/sidekiq/extensions/class_methods.rb on lines 5..38

                  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 73.

                  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

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

                      def normalize_item(item)
                        raise(ArgumentError, "Job must be a Hash with 'class' and 'args' keys: { 'class' => SomeWorker, 'args' => ['bob', 1, :foo => 'bar'] }") unless item.is_a?(Hash) && item.key?("class") && item.key?("args")
                        raise(ArgumentError, "Job args must be an Array") unless item["args"].is_a?(Array)
                        raise(ArgumentError, "Job class must be either a Class or String representation of the class name") unless item["class"].is_a?(Class) || item["class"].is_a?(String)
                        raise(ArgumentError, "Job 'at' must be a Numeric timestamp") if item.key?("at") && !item["at"].is_a?(Numeric)
                  Severity: Minor
                  Found in lib/sidekiq/client.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 has 42 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      def ❤
                        key = identity
                        fails = procd = 0
                  
                        begin
                  Severity: Minor
                  Found in lib/sidekiq/launcher.rb - About 1 hr to fix

                    Method build_sessions has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
                    Open

                        def build_sessions
                          middlewares = self.middlewares
                    
                          unless using?(::Rack::Protection) || ENV["RACK_ENV"] == "test"
                            middlewares.unshift [[::Rack::Protection, {use: :authenticity_token}], nil]
                    Severity: Minor
                    Found in lib/sidekiq/web.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 has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
                    Open

                          def create(options = {})
                            options.keys.each do |key|
                              options[key.to_sym] = options.delete(key)
                            end
                    
                    
                    Severity: Minor
                    Found in lib/sidekiq/redis_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 process has 34 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                        def process(work)
                          jobstr = work.job
                          queue = work.queue_name
                    
                          # Treat malformed JSON as a special case: job goes straight to the morgue.
                    Severity: Minor
                    Found in lib/sidekiq/processor.rb - About 1 hr to fix

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

                          def attempt_retry(worker, msg, queue, exception)
                            max_retry_attempts = retry_attempts_from(msg["retry"], @max_retries)
                      
                            msg["queue"] = (msg["retry_queue"] || queue)
                      
                      
                      Severity: Minor
                      Found in lib/sidekiq/job_retry.rb - About 1 hr to fix

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

                            def page(key, pageidx = 1, page_size = 25, opts = nil)
                              current_page = pageidx.to_i < 1 ? 1 : pageidx.to_i
                              pageidx = current_page - 1
                              total_size = 0
                              items = []
                        Severity: Minor
                        Found in lib/sidekiq/paginator.rb - About 1 hr to fix

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

                                def resolve_class(klass_name)
                                  return nil if !klass_name || klass_name.empty?
                                  # constantize
                                  names = klass_name.split("::")
                                  names.shift if names.empty? || names.first.empty?
                          Severity: Minor
                          Found in lib/sidekiq/delay.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

                          Severity
                          Category
                          Status
                          Source
                          Language