mperham/sidekiq

View on GitHub

Showing 53 of 53 total issues

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

    def remove_job
      Sidekiq.redis do |conn|
        results = conn.multi {
          conn.zrangebyscore(parent.name, score, score)
          conn.zremrangebyscore(parent.name, score, score)
Severity: Minor
Found in lib/sidekiq/api.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 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

Method page has a Cognitive Complexity of 10 (exceeds 5 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

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 redis_info has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

  def self.redis_info
    redis do |conn|
      # admin commands can't go through redis-namespace starting
      # in redis-namespace 2.0
      if conn.respond_to?(:namespace)
Severity: Minor
Found in lib/sidekiq.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 global has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

    def global(msg, queue)
      yield
    rescue Handled => ex
      raise ex
    rescue Sidekiq::Shutdown => ey
Severity: Minor
Found in lib/sidekiq/job_retry.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 27 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    def call(env)
      action = self.class.match(env)
      return [404, {"Content-Type" => "text/plain", "X-Cascade" => "pass"}, ["Not Found"]] unless action

      resp = catch(:halt) {
Severity: Minor
Found in lib/sidekiq/web/application.rb - About 1 hr to fix

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

        def run
          boot_system
          if environment == "development" && $stdout.tty? && Sidekiq.log_formatter.is_a?(Sidekiq::Logger::Formatters::Pretty)
            print_banner
          end
    Severity: Minor
    Found in lib/sidekiq/cli.rb - About 1 hr to fix

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

        def self.redis
          raise ArgumentError, "requires a block" unless block_given?
          redis_pool.with do |conn|
            retryable = true
            begin
      Severity: Minor
      Found in lib/sidekiq.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 attempt_retry has a Cognitive Complexity of 9 (exceeds 5 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 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 delete_by_jid has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

          def delete_by_jid(score, jid)
            Sidekiq.redis do |conn|
              elements = conn.zrangebyscore(name, score, score)
              elements.each do |element|
                message = Sidekiq.load_json(element)
      Severity: Minor
      Found in lib/sidekiq/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 run has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

          def run
            boot_system
            if environment == "development" && $stdout.tty? && Sidekiq.log_formatter.is_a?(Sidekiq::Logger::Formatters::Pretty)
              print_banner
            end
      Severity: Minor
      Found in lib/sidekiq/cli.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 raw_push has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

          def raw_push(payloads)
            if Sidekiq::Testing.fake?
              payloads.each do |job|
                job = Sidekiq.load_json(Sidekiq.dump_json(job))
                job["enqueued_at"] = Time.now.to_f unless job["at"]
      Severity: Minor
      Found in lib/sidekiq/testing.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 local has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

          def local(worker, msg, queue)
            yield
          rescue Handled => ex
            raise ex
          rescue Sidekiq::Shutdown => ey
      Severity: Minor
      Found in lib/sidekiq/job_retry.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

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

          post "/morgue" do
            redirect(request.path) unless params["key"]
      
            params["key"].each do |key|
              job = Sidekiq::DeadSet.new.fetch(*parse_params(key)).first
      Severity: Minor
      Found in lib/sidekiq/web/application.rb and 2 other locations - About 40 mins to fix
      lib/sidekiq/web/application.rb on lines 178..186
      lib/sidekiq/web/application.rb on lines 233..241

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

      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

          post "/retries" do
            redirect(request.path) unless params["key"]
      
            params["key"].each do |key|
              job = Sidekiq::RetrySet.new.fetch(*parse_params(key)).first
      Severity: Minor
      Found in lib/sidekiq/web/application.rb and 2 other locations - About 40 mins to fix
      lib/sidekiq/web/application.rb on lines 127..135
      lib/sidekiq/web/application.rb on lines 233..241

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

      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

          post "/scheduled" do
            redirect(request.path) unless params["key"]
      
            params["key"].each do |key|
              job = Sidekiq::ScheduledSet.new.fetch(*parse_params(key)).first
      Severity: Minor
      Found in lib/sidekiq/web/application.rb and 2 other locations - About 40 mins to fix
      lib/sidekiq/web/application.rb on lines 127..135
      lib/sidekiq/web/application.rb on lines 178..186

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

      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

          get "/scheduled" do
            @count = (params["count"] || 25).to_i
            (@current_page, @total_size, @scheduled) = page("schedule", params["page"], @count)
            @scheduled = @scheduled.map { |msg, score| Sidekiq::SortedEntry.new(nil, score, msg) }
      
      
      Severity: Minor
      Found in lib/sidekiq/web/application.rb and 1 other location - About 35 mins to fix
      lib/sidekiq/web/application.rb on lines 160..165

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

      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

          get "/retries" do
            @count = (params["count"] || 25).to_i
            (@current_page, @total_size, @retries) = page("retry", params["page"], @count)
            @retries = @retries.map { |msg, score| Sidekiq::SortedEntry.new(nil, score, msg) }
      
      
      Severity: Minor
      Found in lib/sidekiq/web/application.rb and 1 other location - About 35 mins to fix
      lib/sidekiq/web/application.rb on lines 215..220

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

      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 enqueue_jobs has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

            def enqueue_jobs(now = Time.now.to_f.to_s, sorted_sets = SETS)
              # A job's "score" in Redis is the time at which it should be processed.
              # Just check Redis for the set of jobs with a timestamp before now.
              Sidekiq.redis do |conn|
                sorted_sets.each do |sorted_set|
      Severity: Minor
      Found in lib/sidekiq/scheduled.rb - 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

      Method user_preferred_languages has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

          def user_preferred_languages
            languages = env["HTTP_ACCEPT_LANGUAGE"]
            languages.to_s.downcase.gsub(/\s+/, "").split(",").map { |language|
              locale, quality = language.split(";q=", 2)
              locale = nil if locale == "*" # Ignore wildcards
      Severity: Minor
      Found in lib/sidekiq/web/helpers.rb - 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

      Severity
      Category
      Status
      Source
      Language