collectiveidea/delayed_job

View on GitHub
lib/delayed/worker.rb

Summary

Maintainability
C
1 day
Test Coverage

Class Worker has 28 methods (exceeds 20 allowed). Consider refactoring.
Open

  class Worker # rubocop:disable ClassLength
    DEFAULT_LOG_LEVEL        = 'info'.freeze
    DEFAULT_SLEEP_DELAY      = 5
    DEFAULT_MAX_ATTEMPTS     = 25
    DEFAULT_MAX_RUN_TIME     = 4.hours
Severity: Minor
Found in lib/delayed/worker.rb - About 3 hrs to fix

    Method start has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
    Open

        def start # rubocop:disable CyclomaticComplexity, PerceivedComplexity
          trap('TERM') do
            Thread.new { say 'Exiting...' }
            stop
            raise SignalException, 'TERM' if self.class.raise_signal_exceptions
    Severity: Minor
    Found in lib/delayed/worker.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

    File worker.rb has 258 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    require 'timeout'
    require 'active_support/dependencies'
    require 'active_support/core_ext/numeric/time'
    require 'active_support/core_ext/class/attribute_accessors'
    require 'active_support/hash_with_indifferent_access'
    Severity: Minor
    Found in lib/delayed/worker.rb - About 2 hrs to fix

      Method start has 33 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def start # rubocop:disable CyclomaticComplexity, PerceivedComplexity
            trap('TERM') do
              Thread.new { say 'Exiting...' }
              stop
              raise SignalException, 'TERM' if self.class.raise_signal_exceptions
      Severity: Minor
      Found in lib/delayed/worker.rb - About 1 hr to fix

        Method work_off has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

            def work_off(num = 100)
              success = 0
              failure = 0
        
              num.times do
        Severity: Minor
        Found in lib/delayed/worker.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

        Method say has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

            def say(text, level = default_log_level)
              text = "[Worker(#{name})] #{text}"
              puts text unless @quiet
              return unless logger
              # TODO: Deprecate use of Fixnum log levels
        Severity: Minor
        Found in lib/delayed/worker.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

        Method before_fork has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

            def self.before_fork
              unless @files_to_reopen
                @files_to_reopen = []
                ObjectSpace.each_object(File) do |file|
                  @files_to_reopen << file unless file.closed?
        Severity: Minor
        Found in lib/delayed/worker.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

        There are no issues that match your filters.

        Category
        Status