shotgunner 0.1.2 → 0.1.7
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/lib/{shotgunner.rb → shotgunner/parallel.rb} +22 -7
- metadata +5 -4
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: f467b5b6f1e41e9fbe2ee7f639412aa95b2a735f4c698033159e5577d7759e26
         | 
| 4 | 
            +
              data.tar.gz: '084a8f4bd422dd8edc9193f7c6edfb30c34e38a15f17f390c66fa54ffa056716'
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 1f33b2f4304e5d61571cd843b2db91552c34c9d894acaa14a189a70da1a4567d20009bd92b1e3f1afae786911f9adf72753b84bb8ad177226a714b67f5aa1306
         | 
| 7 | 
            +
              data.tar.gz: 9f471c6da8bf5ac4e3e36211b6aad0c83f986e8025e985d1c1dd686324a66910c64e10c350e2cb3a4709a99c50199d1ca23c692559264b430313f94c99201a9c
         | 
| @@ -15,20 +15,35 @@ module Shotgunner | |
| 15 15 |  | 
| 16 16 | 
             
                module ClassMethods
         | 
| 17 17 | 
             
                  def run(options = {}, &block)
         | 
| 18 | 
            -
                    mutex =  | 
| 19 | 
            -
                     | 
| 20 | 
            -
                    tasks  | 
| 21 | 
            -
                     | 
| 22 | 
            -
                    call_results = []
         | 
| 18 | 
            +
                    call_results, mutex, tasks, threads = initiate(options)
         | 
| 19 | 
            +
                    
         | 
| 20 | 
            +
                    validate_params(tasks, threads)
         | 
| 21 | 
            +
                    
         | 
| 23 22 | 
             
                    threads.times.map do
         | 
| 24 23 | 
             
                      Thread.new(tasks, call_results) do |tasks, call_results|
         | 
| 25 24 | 
             
                        while (task = mutex.synchronize { tasks.pop })
         | 
| 26 25 | 
             
                          call_result = yield(task)
         | 
| 27 | 
            -
                          mutex.synchronize { call_results  | 
| 26 | 
            +
                          mutex.synchronize { call_results[task] = call_result }
         | 
| 28 27 | 
             
                        end
         | 
| 29 28 | 
             
                      end
         | 
| 30 29 | 
             
                    end.each(&:join)
         | 
| 31 | 
            -
                     | 
| 30 | 
            +
                    
         | 
| 31 | 
            +
                    call_results.map{|v| v[1]}
         | 
| 32 | 
            +
                  end
         | 
| 33 | 
            +
             | 
| 34 | 
            +
                  private
         | 
| 35 | 
            +
                  
         | 
| 36 | 
            +
                  def validate_params(tasks, threads)
         | 
| 37 | 
            +
                    raise ArgumentError, 'There is no tasks array defined!' if tasks.empty?
         | 
| 38 | 
            +
                    raise ArgumentError, 'Invalid threads number, please select number from 1..100' unless threads&.between?(1, 100)
         | 
| 39 | 
            +
                  end
         | 
| 40 | 
            +
             | 
| 41 | 
            +
                  def initiate(options)
         | 
| 42 | 
            +
                    mutex = Mutex.new
         | 
| 43 | 
            +
                    threads = options[:threads] || 4
         | 
| 44 | 
            +
                    tasks = options[:tasks]&.dup || []
         | 
| 45 | 
            +
                    call_results = Hash[tasks.map { |x| [x, nil] }]
         | 
| 46 | 
            +
                    [call_results, mutex, tasks, threads]
         | 
| 32 47 | 
             
                  end
         | 
| 33 48 | 
             
                end
         | 
| 34 49 | 
             
              end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: shotgunner
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.1. | 
| 4 | 
            +
              version: 0.1.7
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Oleg Saltykov
         | 
| 8 8 | 
             
            autorequire:
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2021- | 
| 11 | 
            +
            date: 2021-05-04 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies: []
         | 
| 13 13 | 
             
            description:
         | 
| 14 14 | 
             
            email:
         | 
| @@ -16,9 +16,10 @@ executables: [] | |
| 16 16 | 
             
            extensions: []
         | 
| 17 17 | 
             
            extra_rdoc_files: []
         | 
| 18 18 | 
             
            files:
         | 
| 19 | 
            -
            - lib/shotgunner.rb
         | 
| 19 | 
            +
            - lib/shotgunner/parallel.rb
         | 
| 20 20 | 
             
            homepage: https://github.com/nucleom42/shotgunner
         | 
| 21 | 
            -
            licenses: | 
| 21 | 
            +
            licenses:
         | 
| 22 | 
            +
            - MIT
         | 
| 22 23 | 
             
            metadata: {}
         | 
| 23 24 | 
             
            post_install_message:
         | 
| 24 25 | 
             
            rdoc_options: []
         |