worker_tools 0.2.1 → 0.2.2
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/README.md +47 -0
- data/lib/worker_tools/basics.rb +1 -0
- data/lib/worker_tools/benchmark.rb +15 -0
- data/lib/worker_tools/counters.rb +41 -0
- data/lib/worker_tools/recorder.rb +1 -0
- data/lib/worker_tools/version.rb +1 -1
- metadata +9 -7
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: a53ae86156768dd1b1f80601a50f8c6926918d3f625be933173f7d4513c0f2d8
         | 
| 4 | 
            +
              data.tar.gz: 48dfc8c5430311e2b6dae3d5bfbb55d6d2ce0444d3c5e5dd5a9cf044e42afdf7
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 95ac0fe0d5255b995a5c7a0193edf6a56eb5d376234e1f6088f6c97ad03ea6e760d499c62c2c711f5ad2b453f5c9f7b5309f9bea2acfb50b9c60621b83ed3800
         | 
| 7 | 
            +
              data.tar.gz: e2a09d6b64d813a0296f81d5ef995ed49178957bfdbf67349e5b2d811ec84e98b08850e9565f875f02a6b105f9ae9769cfd177d660b2a4d98bf0b2ae03ecf77c
         | 
    
        data/README.md
    CHANGED
    
    | @@ -59,6 +59,7 @@ In this case the migration would be something like this: | |
| 59 59 | 
             
                  t.integer :state, default: 0, null: false
         | 
| 60 60 | 
             
                  t.text :information
         | 
| 61 61 | 
             
                  t.json  :options, default: {}
         | 
| 62 | 
            +
                  t.json :meta, default: {}
         | 
| 62 63 |  | 
| 63 64 | 
             
                  t.string :attachment_file_name
         | 
| 64 65 | 
             
                  t.integer :attachment_file_size
         | 
| @@ -199,6 +200,52 @@ def perform(model_id) | |
| 199 200 | 
             
            end
         | 
| 200 201 | 
             
            ```
         | 
| 201 202 |  | 
| 203 | 
            +
            ## Counters
         | 
| 204 | 
            +
             | 
| 205 | 
            +
            There is a counter wrapper that you can use to add custom counters to the meta attribute. To do this, you need to complete the following tasks:
         | 
| 206 | 
            +
            - include WorkerTools::Counters to your class
         | 
| 207 | 
            +
            - add :counters to the wrappers method props
         | 
| 208 | 
            +
            - call counters method with your custom counters
         | 
| 209 | 
            +
            You can see an example below. After that, you can access your custom counters via the meta attribute.
         | 
| 210 | 
            +
             | 
| 211 | 
            +
            ```ruby
         | 
| 212 | 
            +
            class MyImporter
         | 
| 213 | 
            +
              include WorkerTools::Counters
         | 
| 214 | 
            +
              wrappers :counters
         | 
| 215 | 
            +
              counters :foo, :bar
         | 
| 216 | 
            +
             | 
| 217 | 
            +
              def run
         | 
| 218 | 
            +
                example_foo_counter_methods
         | 
| 219 | 
            +
              end
         | 
| 220 | 
            +
             | 
| 221 | 
            +
              def example_foo_counter_methods
         | 
| 222 | 
            +
                self.foo = 0
         | 
| 223 | 
            +
             | 
| 224 | 
            +
                10.times { increment_foo }
         | 
| 225 | 
            +
             | 
| 226 | 
            +
                puts foo # foo == 10
         | 
| 227 | 
            +
              end
         | 
| 228 | 
            +
              
         | 
| 229 | 
            +
              # ..
         | 
| 230 | 
            +
            end
         | 
| 231 | 
            +
            ```
         | 
| 232 | 
            +
             | 
| 233 | 
            +
            ## Benchmark
         | 
| 234 | 
            +
             | 
| 235 | 
            +
            There is a benchmark wrapper that you can use to record the benchmark. The only thing you need to do is to include the benchmark module and append the name to the wrapper array. Below you can see an example of the integration.
         | 
| 236 | 
            +
             | 
| 237 | 
            +
            ```ruby
         | 
| 238 | 
            +
            class MyImporter
         | 
| 239 | 
            +
              include WorkerTools::CustomBenchmark
         | 
| 240 | 
            +
              wrappers :benchmark
         | 
| 241 | 
            +
             | 
| 242 | 
            +
              def run
         | 
| 243 | 
            +
                # do stuff
         | 
| 244 | 
            +
              end
         | 
| 245 | 
            +
             | 
| 246 | 
            +
              # ..
         | 
| 247 | 
            +
            end
         | 
| 248 | 
            +
            ```
         | 
| 202 249 |  | 
| 203 250 | 
             
            ## Contributing
         | 
| 204 251 |  | 
    
        data/lib/worker_tools/basics.rb
    CHANGED
    
    
| @@ -0,0 +1,15 @@ | |
| 1 | 
            +
            module WorkerTools
         | 
| 2 | 
            +
              module CustomBenchmark
         | 
| 3 | 
            +
                extend ActiveSupport::Concern
         | 
| 4 | 
            +
             | 
| 5 | 
            +
                included do
         | 
| 6 | 
            +
                  attr_accessor :benchmark
         | 
| 7 | 
            +
             | 
| 8 | 
            +
                  def with_wrapper_benchmark(&block)
         | 
| 9 | 
            +
                    @benchmark = Benchmark.measure(&block)
         | 
| 10 | 
            +
             | 
| 11 | 
            +
                    model.meta['duration'] = @benchmark.real.round if model.respond_to?(:meta)
         | 
| 12 | 
            +
                  end
         | 
| 13 | 
            +
                end
         | 
| 14 | 
            +
              end
         | 
| 15 | 
            +
            end
         | 
| @@ -0,0 +1,41 @@ | |
| 1 | 
            +
            module WorkerTools
         | 
| 2 | 
            +
              module Counters
         | 
| 3 | 
            +
                extend ActiveSupport::Concern
         | 
| 4 | 
            +
             | 
| 5 | 
            +
                included do
         | 
| 6 | 
            +
                  def self.counters(*args)
         | 
| 7 | 
            +
                    @counters ||= args.flatten
         | 
| 8 | 
            +
                    add_counter_methods
         | 
| 9 | 
            +
                  end
         | 
| 10 | 
            +
             | 
| 11 | 
            +
                  def self.read_counters
         | 
| 12 | 
            +
                    @counters || []
         | 
| 13 | 
            +
                  end
         | 
| 14 | 
            +
             | 
| 15 | 
            +
                  def self.add_counter_methods
         | 
| 16 | 
            +
                    @counters.each do |name|
         | 
| 17 | 
            +
                      define_method name do
         | 
| 18 | 
            +
                        model.meta[name]
         | 
| 19 | 
            +
                      end
         | 
| 20 | 
            +
                      define_method "#{name}=" do |value|
         | 
| 21 | 
            +
                        model.meta[name] = value
         | 
| 22 | 
            +
                      end
         | 
| 23 | 
            +
                      define_method "increment_#{name}" do
         | 
| 24 | 
            +
                        model.meta[name] += 1
         | 
| 25 | 
            +
                      end
         | 
| 26 | 
            +
                    end
         | 
| 27 | 
            +
                  end
         | 
| 28 | 
            +
             | 
| 29 | 
            +
                  def with_wrapper_counters(&block)
         | 
| 30 | 
            +
                    reset_counters
         | 
| 31 | 
            +
                    block.call
         | 
| 32 | 
            +
                  end
         | 
| 33 | 
            +
             | 
| 34 | 
            +
                  def reset_counters
         | 
| 35 | 
            +
                    self.class.read_counters.each do |name|
         | 
| 36 | 
            +
                      model.meta[name] = 0
         | 
| 37 | 
            +
                    end
         | 
| 38 | 
            +
                  end
         | 
| 39 | 
            +
                end
         | 
| 40 | 
            +
              end
         | 
| 41 | 
            +
            end
         | 
    
        data/lib/worker_tools/version.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: worker_tools
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.2. | 
| 4 | 
            +
              version: 0.2.2
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - fsainz
         | 
| 8 | 
            -
            autorequire: | 
| 8 | 
            +
            autorequire:
         | 
| 9 9 | 
             
            bindir: exe
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date:  | 
| 11 | 
            +
            date: 2022-04-21 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: activesupport
         | 
| @@ -220,7 +220,7 @@ dependencies: | |
| 220 220 | 
             
                - - ">="
         | 
| 221 221 | 
             
                  - !ruby/object:Gem::Version
         | 
| 222 222 | 
             
                    version: '0'
         | 
| 223 | 
            -
            description: | 
| 223 | 
            +
            description:
         | 
| 224 224 | 
             
            email:
         | 
| 225 225 | 
             
            - fernando.sainz@i22.de
         | 
| 226 226 | 
             
            executables: []
         | 
| @@ -238,6 +238,8 @@ files: | |
| 238 238 | 
             
            - bin/setup
         | 
| 239 239 | 
             
            - lib/worker_tools.rb
         | 
| 240 240 | 
             
            - lib/worker_tools/basics.rb
         | 
| 241 | 
            +
            - lib/worker_tools/benchmark.rb
         | 
| 242 | 
            +
            - lib/worker_tools/counters.rb
         | 
| 241 243 | 
             
            - lib/worker_tools/csv_input.rb
         | 
| 242 244 | 
             
            - lib/worker_tools/csv_output.rb
         | 
| 243 245 | 
             
            - lib/worker_tools/recorder.rb
         | 
| @@ -251,7 +253,7 @@ licenses: | |
| 251 253 | 
             
            - MIT
         | 
| 252 254 | 
             
            metadata:
         | 
| 253 255 | 
             
              allowed_push_host: https://rubygems.org
         | 
| 254 | 
            -
            post_install_message: | 
| 256 | 
            +
            post_install_message:
         | 
| 255 257 | 
             
            rdoc_options: []
         | 
| 256 258 | 
             
            require_paths:
         | 
| 257 259 | 
             
            - lib
         | 
| @@ -266,8 +268,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement | |
| 266 268 | 
             
                - !ruby/object:Gem::Version
         | 
| 267 269 | 
             
                  version: '0'
         | 
| 268 270 | 
             
            requirements: []
         | 
| 269 | 
            -
            rubygems_version: 3.1. | 
| 270 | 
            -
            signing_key: | 
| 271 | 
            +
            rubygems_version: 3.1.4
         | 
| 272 | 
            +
            signing_key:
         | 
| 271 273 | 
             
            specification_version: 4
         | 
| 272 274 | 
             
            summary: A collection of modules to help writing common worker tasks)
         | 
| 273 275 | 
             
            test_files: []
         |