nanodeath/threadz

View on GitHub

Showing 8 of 8 total issues

Method spawn_watch_thread has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
Open

    def spawn_watch_thread
      @watch_thread = Thread.new do
        while true
          # If there are idle threads and we're above minimum
          if @queue.num_waiting > 0 && @worker_threads_count.value > @min_size # documented
Severity: Minor
Found in lib/threadz/thread_pool.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 send_to_threadpool has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
Open

    def send_to_threadpool(job)
      @threadpool.process do
        control = Control.new(job)
        retries = 0
        begin
Severity: Minor
Found in lib/threadz/batch.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 send_to_threadpool has 27 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    def send_to_threadpool(job)
      @threadpool.process do
        control = Control.new(job)
        retries = 0
        begin
Severity: Minor
Found in lib/threadz/batch.rb - About 1 hr to fix

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

        def spawn_thread
          Thread.new do
            while true
              x = @queue.shift
              if x == Directive::SUICIDE_PILL
    Severity: Minor
    Found in lib/threadz/thread_pool.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 initialize has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

        def initialize(threadpool, opts={})
          @threadpool = threadpool
          @job_lock = Mutex.new
          @jobs_count = AtomicInteger.new(0)
          @when_done_callbacks = []
    Severity: Minor
    Found in lib/threadz/batch.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 push has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

        def push(job)
          if job.is_a? Array
            job.each { |j| self.push(j) }
          elsif job.respond_to? :call
            @jobs_count.increment
    Severity: Minor
    Found in lib/threadz/batch.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 wait_until_done has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

        def wait_until_done(opts={})
          raise "Threadz: thread deadlocked because batch job was never started" if @latent && !@started
    
          timeout = opts.key?(:timeout) ? opts[:timeout] : 0
          @sleeper.wait(timeout) unless completed?
    Severity: Minor
    Found in lib/threadz/batch.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 start has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

        def start
          @job_lock.synchronize do  # in case another thread tries to push new jobs onto the queue while we're starting
            if @latent && !@started
              @started = true
              until @job_queue.empty?
    Severity: Minor
    Found in lib/threadz/batch.rb - 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