ci-queue 0.23.1 → 0.24.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/dev.yml +1 -1
- data/{railgun.yml → isogun.yml} +0 -3
- data/lib/ci/queue/configuration.rb +12 -2
- data/lib/ci/queue/redis/base.rb +10 -0
- data/lib/ci/queue/redis/supervisor.rb +19 -3
- data/lib/ci/queue/redis/worker.rb +2 -0
- data/lib/ci/queue/version.rb +1 -1
- data/lib/minitest/queue/runner.rb +27 -1
- metadata +3 -3
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 5f51b9eaf62e347a724e6e1fc533c26d504cca7922a4296b750ae2599c7cfa6e
         | 
| 4 | 
            +
              data.tar.gz: 0b9833d46d95e90d67663a2ff5bea2a8ad17c781b812a9f8b4ec7485bf0789d0
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: b627008782774ad37ae5dbd5a2db0ae24df1f3fcda1dae9e0c0064f7c8df7890b926734855fd0f35d440e5e03d25441b6b9dc60c48bcaa19b8c5537c5d33c98b
         | 
| 7 | 
            +
              data.tar.gz: e3d1c41abfe02341deb545fda1e6eebb94826801ca104788d2aa48fab1886e6093acd402ef097f58c6b2bc4f403568386e45d1b8032f1323d4f7cfbf6f7f381b
         | 
    
        data/dev.yml
    CHANGED
    
    
    
        data/{railgun.yml → isogun.yml}
    RENAMED
    
    
| @@ -8,7 +8,7 @@ module CI | |
| 8 8 | 
             
                  attr_accessor :max_test_failed, :redis_ttl
         | 
| 9 9 | 
             
                  attr_reader :circuit_breakers
         | 
| 10 10 | 
             
                  attr_writer :seed, :build_id
         | 
| 11 | 
            -
                  attr_writer :queue_init_timeout
         | 
| 11 | 
            +
                  attr_writer :queue_init_timeout, :report_timeout, :inactive_workers_timeout
         | 
| 12 12 |  | 
| 13 13 | 
             
                  class << self
         | 
| 14 14 | 
             
                    def from_env(env)
         | 
| @@ -35,7 +35,7 @@ module CI | |
| 35 35 | 
             
                    namespace: nil, seed: nil, flaky_tests: [], statsd_endpoint: nil, max_consecutive_failures: nil,
         | 
| 36 36 | 
             
                    grind_count: nil, max_duration: nil, failure_file: nil, max_test_duration: nil,
         | 
| 37 37 | 
             
                    max_test_duration_percentile: 0.5, track_test_duration: false, max_test_failed: nil,
         | 
| 38 | 
            -
                    queue_init_timeout: nil, redis_ttl: 8 * 60 * 60
         | 
| 38 | 
            +
                    queue_init_timeout: nil, redis_ttl: 8 * 60 * 60, report_timeout: nil, inactive_workers_timeout: nil
         | 
| 39 39 | 
             
                  )
         | 
| 40 40 | 
             
                    @build_id = build_id
         | 
| 41 41 | 
             
                    @circuit_breakers = [CircuitBreaker::Disabled]
         | 
| @@ -57,12 +57,22 @@ module CI | |
| 57 57 | 
             
                    self.max_consecutive_failures = max_consecutive_failures
         | 
| 58 58 | 
             
                    self.max_duration = max_duration
         | 
| 59 59 | 
             
                    @redis_ttl = redis_ttl
         | 
| 60 | 
            +
                    @report_timeout = report_timeout
         | 
| 61 | 
            +
                    @inactive_workers_timeout = inactive_workers_timeout
         | 
| 60 62 | 
             
                  end
         | 
| 61 63 |  | 
| 62 64 | 
             
                  def queue_init_timeout
         | 
| 63 65 | 
             
                    @queue_init_timeout || timeout
         | 
| 64 66 | 
             
                  end
         | 
| 65 67 |  | 
| 68 | 
            +
                  def report_timeout
         | 
| 69 | 
            +
                    @report_timeout || timeout
         | 
| 70 | 
            +
                  end
         | 
| 71 | 
            +
             | 
| 72 | 
            +
                  def inactive_workers_timeout
         | 
| 73 | 
            +
                    @inactive_workers_timeout || timeout
         | 
| 74 | 
            +
                  end
         | 
| 75 | 
            +
             | 
| 66 76 | 
             
                  def max_consecutive_failures=(max)
         | 
| 67 77 | 
             
                    if max
         | 
| 68 78 | 
             
                      @circuit_breakers << CircuitBreaker::MaxConsecutiveFailures.new(max_consecutive_failures: max)
         | 
    
        data/lib/ci/queue/redis/base.rb
    CHANGED
    
    | @@ -5,6 +5,7 @@ module CI | |
| 5 5 | 
             
                  class Base
         | 
| 6 6 | 
             
                    include Common
         | 
| 7 7 |  | 
| 8 | 
            +
                    TEN_MINUTES = 60 * 10
         | 
| 8 9 | 
             
                    CONNECTION_ERRORS = [
         | 
| 9 10 | 
             
                      ::Redis::BaseConnectionError,
         | 
| 10 11 | 
             
                      ::SocketError, # https://github.com/redis/redis-rb/pull/631
         | 
| @@ -20,6 +21,15 @@ module CI | |
| 20 21 | 
             
                      queue_initialized? && size == 0
         | 
| 21 22 | 
             
                    end
         | 
| 22 23 |  | 
| 24 | 
            +
                    def expired?
         | 
| 25 | 
            +
                      if (created_at = redis.get(key('master-created-at')))
         | 
| 26 | 
            +
                        (created_at.to_f + config.redis_ttl + TEN_MINUTES) < Time.now.to_f
         | 
| 27 | 
            +
                      else
         | 
| 28 | 
            +
                        # if there is no created at set anymore we assume queue is expired
         | 
| 29 | 
            +
                        true
         | 
| 30 | 
            +
                      end
         | 
| 31 | 
            +
                    end
         | 
| 32 | 
            +
             | 
| 23 33 | 
             
                    def size
         | 
| 24 34 | 
             
                      redis.multi do |transaction|
         | 
| 25 35 | 
             
                        transaction.llen(key('queue'))
         | 
| @@ -21,17 +21,33 @@ module CI | |
| 21 21 |  | 
| 22 22 | 
             
                      yield if block_given?
         | 
| 23 23 |  | 
| 24 | 
            -
                      time_left = config. | 
| 25 | 
            -
                       | 
| 26 | 
            -
             | 
| 24 | 
            +
                      time_left = config.report_timeout
         | 
| 25 | 
            +
                      time_left_with_no_workers = config.inactive_workers_timeout
         | 
| 26 | 
            +
                      until exhausted? || time_left <= 0 || max_test_failed? || time_left_with_no_workers <= 0
         | 
| 27 27 | 
             
                        time_left -= 1
         | 
| 28 | 
            +
                        sleep 1
         | 
| 29 | 
            +
             | 
| 30 | 
            +
                        if active_workers?
         | 
| 31 | 
            +
                          time_left_with_no_workers = config.inactive_workers_timeout
         | 
| 32 | 
            +
                        else
         | 
| 33 | 
            +
                          time_left_with_no_workers -= 1
         | 
| 34 | 
            +
                        end
         | 
| 28 35 |  | 
| 29 36 | 
             
                        yield if block_given?
         | 
| 30 37 | 
             
                      end
         | 
| 38 | 
            +
             | 
| 39 | 
            +
                      puts "Aborting, it seems all workers died." if time_left_with_no_workers <= 0
         | 
| 31 40 | 
             
                      exhausted?
         | 
| 32 41 | 
             
                    rescue CI::Queue::Redis::LostMaster
         | 
| 33 42 | 
             
                      false
         | 
| 34 43 | 
             
                    end
         | 
| 44 | 
            +
             | 
| 45 | 
            +
                    private
         | 
| 46 | 
            +
             | 
| 47 | 
            +
                    def active_workers?
         | 
| 48 | 
            +
                      # if there are running jobs we assume there are still agents active
         | 
| 49 | 
            +
                      redis.zrangebyscore(key('running'), Time.now.to_f - config.timeout, "+inf", limit: [0,1]).count > 0
         | 
| 50 | 
            +
                    end
         | 
| 35 51 | 
             
                  end
         | 
| 36 52 | 
             
                end
         | 
| 37 53 | 
             
              end
         | 
| @@ -202,10 +202,12 @@ module CI | |
| 202 202 | 
             
                          transaction.lpush(key('queue'), tests) unless tests.empty?
         | 
| 203 203 | 
             
                          transaction.set(key('total'), @total)
         | 
| 204 204 | 
             
                          transaction.set(key('master-status'), 'ready')
         | 
| 205 | 
            +
                          transaction.set(key('master-created-at'), Time.now.to_f)
         | 
| 205 206 |  | 
| 206 207 | 
             
                          transaction.expire(key('queue'), config.redis_ttl)
         | 
| 207 208 | 
             
                          transaction.expire(key('total'), config.redis_ttl)
         | 
| 208 209 | 
             
                          transaction.expire(key('master-status'), config.redis_ttl)
         | 
| 210 | 
            +
                          transaction.expire(key('master-created-at'), config.redis_ttl)
         | 
| 209 211 | 
             
                        end
         | 
| 210 212 | 
             
                      end
         | 
| 211 213 | 
             
                      register
         | 
    
        data/lib/ci/queue/version.rb
    CHANGED
    
    
| @@ -47,7 +47,10 @@ module Minitest | |
| 47 47 | 
             
                  end
         | 
| 48 48 |  | 
| 49 49 | 
             
                  def run_command
         | 
| 50 | 
            -
                    if queue.retrying?
         | 
| 50 | 
            +
                    if queue.retrying? || retry?
         | 
| 51 | 
            +
                      if queue.expired?
         | 
| 52 | 
            +
                        abort! "The test run is too old and can't be retried"
         | 
| 53 | 
            +
                      end
         | 
| 51 54 | 
             
                      reset_counters
         | 
| 52 55 | 
             
                      retry_queue = queue.retry_queue
         | 
| 53 56 | 
             
                      if retry_queue.exhausted?
         | 
| @@ -367,6 +370,24 @@ module Minitest | |
| 367 370 | 
             
                        queue_config.timeout = timeout
         | 
| 368 371 | 
             
                      end
         | 
| 369 372 |  | 
| 373 | 
            +
                      help = <<~EOS
         | 
| 374 | 
            +
                        Specify a timeout after which the report command will fail if not all tests have been processed.
         | 
| 375 | 
            +
                        Defaults to the value set for --timeout.
         | 
| 376 | 
            +
                      EOS
         | 
| 377 | 
            +
                      opts.separator ""
         | 
| 378 | 
            +
                      opts.on('--report-timeout TIMEOUT', Float, help) do |timeout|
         | 
| 379 | 
            +
                        queue_config.report_timeout = timeout
         | 
| 380 | 
            +
                      end
         | 
| 381 | 
            +
             | 
| 382 | 
            +
                      help = <<~EOS
         | 
| 383 | 
            +
                        Specify a timeout after the report will fail if all workers are inactive (e.g. died).
         | 
| 384 | 
            +
                        Defaults to the value set for --timeout.
         | 
| 385 | 
            +
                      EOS
         | 
| 386 | 
            +
                      opts.separator ""
         | 
| 387 | 
            +
                      opts.on('--inactive-workers-timeout TIMEOUT', Float, help) do |timeout|
         | 
| 388 | 
            +
                        queue_config.inactive_workers_timeout = timeout
         | 
| 389 | 
            +
                      end
         | 
| 390 | 
            +
             | 
| 370 391 | 
             
                      help = <<~EOS
         | 
| 371 392 | 
             
                        Specify a timeout to elect the leader and populate the queue.
         | 
| 372 393 | 
             
                        Defaults to the value set for --timeout.
         | 
| @@ -546,6 +567,11 @@ module Minitest | |
| 546 567 | 
             
                    puts red(message)
         | 
| 547 568 | 
             
                    exit! 1 # exit! is required to avoid minitest at_exit callback
         | 
| 548 569 | 
             
                  end
         | 
| 570 | 
            +
             | 
| 571 | 
            +
                  def retry?
         | 
| 572 | 
            +
                    ENV["BUILDKITE_RETRY_COUNT"].to_i > 0 ||
         | 
| 573 | 
            +
                      ENV["SEMAPHORE_PIPELINE_RERUN"] == "true"
         | 
| 574 | 
            +
                  end
         | 
| 549 575 | 
             
                end
         | 
| 550 576 | 
             
              end
         | 
| 551 577 | 
             
            end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: ci-queue
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0. | 
| 4 | 
            +
              version: 0.24.0
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Jean Boussier
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: exe
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2022- | 
| 11 | 
            +
            date: 2022-07-20 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: bundler
         | 
| @@ -171,6 +171,7 @@ files: | |
| 171 171 | 
             
            - dev.yml
         | 
| 172 172 | 
             
            - exe/minitest-queue
         | 
| 173 173 | 
             
            - exe/rspec-queue
         | 
| 174 | 
            +
            - isogun.yml
         | 
| 174 175 | 
             
            - lib/ci/queue.rb
         | 
| 175 176 | 
             
            - lib/ci/queue/bisect.rb
         | 
| 176 177 | 
             
            - lib/ci/queue/build_record.rb
         | 
| @@ -218,7 +219,6 @@ files: | |
| 218 219 | 
             
            - lib/rspec/queue.rb
         | 
| 219 220 | 
             
            - lib/rspec/queue/build_status_recorder.rb
         | 
| 220 221 | 
             
            - lib/rspec/queue/order_recorder.rb
         | 
| 221 | 
            -
            - railgun.yml
         | 
| 222 222 | 
             
            homepage: https://github.com/Shopify/ci-queue
         | 
| 223 223 | 
             
            licenses:
         | 
| 224 224 | 
             
            - MIT
         |