upperkut 0.3.0 → 0.4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 86cdd27d527086fd910ae6065716239959e2948b
4
- data.tar.gz: 2556072af6d5b2ba93dffdcccb3c2c8f7dd7da22
3
+ metadata.gz: 837693381be84b252c08cf7078f1cf5b6d7b54db
4
+ data.tar.gz: 9a6d1e0240d2d26d7c44b1b997c8b8808e043c0a
5
5
  SHA512:
6
- metadata.gz: 2d758d766b00c8a094d1a83a97a1632abfdbc6406867c47379e54876a837232c526be01bb4e1aea723852c6e0af8f248afae584f3ad053dbd8311f7bd1aec019
7
- data.tar.gz: ced16ccf12783e7a23f4cb13405da13a9c1a860b6e0b607a1822ac9feb6f3545fb2cada50a930c9df04fe8e973cbef4962d5e7f773feb2457848565138cdc90d
6
+ metadata.gz: e9bcf4d0f46b33feddb133cac352861148e6db064d3c714447ce8b25f03eeb766f4c88516d1a6a522f93af4e51a85bfb55effa7db0e56e6204e4e9102a76ed5b
7
+ data.tar.gz: cfcacc14f495f5121a3d86d3f57752eab98a8010cd26fe4fcef6d7b4c1552a5077d2d8ad2e3c8f11e4d7f81340a2d3617cc8dc0f7227ecdcb95c8c7993c9d70f
@@ -0,0 +1,63 @@
1
+ # Ruby CircleCI 2.0 configuration file
2
+ #
3
+ # Check https://circleci.com/docs/2.0/language-ruby/ for more details
4
+ #
5
+ version: 2
6
+ jobs:
7
+ build:
8
+ docker:
9
+ - image: circleci/ruby:2.4.4
10
+ environment:
11
+ CC_TEST_REPORTER_ID: 03ab83a772148a577d29d4acf438d7ebdc95c632224122d0ba8dbb291eedebe6
12
+ COVERAGE: true
13
+ steps:
14
+ - checkout
15
+
16
+ # Download and cache dependencies
17
+ - restore_cache:
18
+ keys:
19
+ - v1-dependencies-{{ checksum "Gemfile.lock" }}
20
+ # fallback to using the latest cache if no exact match is found
21
+ - v1-dependencies-
22
+
23
+ - run:
24
+ name: install dependencies
25
+ command: |
26
+ bundle install --jobs=4 --retry=3 --path vendor/bundle
27
+
28
+ - save_cache:
29
+ paths:
30
+ - ./vendor/bundle
31
+ key: v1-dependencies-{{ checksum "Gemfile.lock" }}
32
+
33
+ - run:
34
+ name: Setup Code Climate test-reporter
35
+ command: |
36
+ curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
37
+ chmod +x ./cc-test-reporter
38
+ ./cc-test-reporter before-build
39
+
40
+ # run tests!
41
+ - run:
42
+ name: run tests
43
+ command: |
44
+ mkdir /tmp/test-results
45
+ TEST_FILES="$(circleci tests glob "spec/**/*_spec.rb" | circleci tests split --split-by=timings)"
46
+
47
+ bundle exec rspec --format progress \
48
+ --format RspecJunitFormatter \
49
+ --out /tmp/test-results/rspec.xml \
50
+ --format progress \
51
+ $TEST_FILES
52
+ - run:
53
+ name: Submit coverage
54
+ command: |
55
+ ./cc-test-reporter after-build --coverage-input-type simplecov --exit-code $?
56
+
57
+ # collect reports
58
+ - store_test_results:
59
+ path: /tmp/test-results
60
+
61
+ - store_artifacts:
62
+ path: /tmp/test-results
63
+ destination: test-results
data/Gemfile CHANGED
@@ -6,4 +6,7 @@ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
6
6
  gemspec
7
7
 
8
8
  gem 'fakeredis'
9
+ gem 'fivemat'
9
10
  gem 'pry'
11
+ gem 'rspec_junit_formatter'
12
+ gem 'simplecov', require: false
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- upperkut (0.3.0)
4
+ upperkut (0.1.4)
5
5
  redis (>= 3.3.5, < 5)
6
6
 
7
7
  GEM
@@ -9,8 +9,11 @@ GEM
9
9
  specs:
10
10
  coderay (1.1.2)
11
11
  diff-lcs (1.3)
12
+ docile (1.3.1)
12
13
  fakeredis (0.7.0)
13
14
  redis (>= 3.2, < 5.0)
15
+ fivemat (1.3.6)
16
+ json (2.1.0)
14
17
  method_source (0.9.0)
15
18
  pry (0.11.3)
16
19
  coderay (~> 1.1.0)
@@ -30,6 +33,13 @@ GEM
30
33
  diff-lcs (>= 1.2.0, < 2.0)
31
34
  rspec-support (~> 3.7.0)
32
35
  rspec-support (3.7.1)
36
+ rspec_junit_formatter (0.4.1)
37
+ rspec-core (>= 2, < 4, != 2.12.0)
38
+ simplecov (0.16.1)
39
+ docile (~> 1.1)
40
+ json (>= 1.8, < 3)
41
+ simplecov-html (~> 0.10.0)
42
+ simplecov-html (0.10.2)
33
43
 
34
44
  PLATFORMS
35
45
  ruby
@@ -37,9 +47,12 @@ PLATFORMS
37
47
  DEPENDENCIES
38
48
  bundler (~> 1.16)
39
49
  fakeredis
50
+ fivemat
40
51
  pry
41
52
  rake (~> 10.0)
42
53
  rspec (~> 3.0)
54
+ rspec_junit_formatter
55
+ simplecov
43
56
  upperkut!
44
57
 
45
58
  BUNDLED WITH
data/README.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Upperkut
2
2
 
3
+ [![CircleCI](https://circleci.com/gh/ResultadosDigitais/upperkut/tree/master.svg?style=svg&circle-token=693e512de6985be3b3db12279ba6ed508fb5c6f6)](https://circleci.com/gh/ResultadosDigitais/upperkut/tree/master)
4
+ [![Maintainability](https://api.codeclimate.com/v1/badges/ece40319b0db03af891d/maintainability)](https://codeclimate.com/repos/5b318a7c6d37b70272008676/maintainability)
5
+ [![Test Coverage](https://api.codeclimate.com/v1/badges/ece40319b0db03af891d/test_coverage)](https://codeclimate.com/repos/5b318a7c6d37b70272008676/test_coverage)
6
+
3
7
  Batch background processing tool.
4
8
 
5
9
  ## Installation
@@ -72,7 +76,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
72
76
 
73
77
  ## Contributing
74
78
 
75
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/upperkut. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
79
+ Bug reports and pull requests are welcome on GitHub at https://github.com/ResultadosDigitais/upperkut. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
76
80
 
77
81
  ## License
78
82
 
@@ -80,4 +84,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
80
84
 
81
85
  ## Code of Conduct
82
86
 
83
- Everyone interacting in the Upperkut project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/upperkut/blob/master/CODE_OF_CONDUCT.md).
87
+ Everyone interacting in the Upperkut project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/ResultadosDigitais/upperkut/blob/master/CODE_OF_CONDUCT.md).
data/examples/basic.rb CHANGED
@@ -5,7 +5,7 @@ class MyWorker
5
5
 
6
6
  def perform(items)
7
7
  puts 'starting performing'
8
- exec_time = rand(90..500)
8
+ exec_time = rand(9000..50000)
9
9
  sleep (exec_time.to_f / 1000.to_f)
10
10
  puts "performed #{items.size} items in #{exec_time.to_f / 1000.to_f} ms"
11
11
  end
@@ -0,0 +1,27 @@
1
+ require_relative '../lib/upperkut/worker'
2
+
3
+ class MyMiddleware
4
+ def call(worker, items)
5
+ logger = Upperkut::Logging.logger
6
+
7
+ logger.info("performing worker=#{worker} items=#{items.count}")
8
+ yield
9
+ logger.info("performed worker=#{worker} items=#{items.count}")
10
+ end
11
+ end
12
+
13
+ class WithMiddlewares
14
+ include Upperkut::Worker
15
+
16
+ setup_upperkut do |config|
17
+ config.middlewares do |chain|
18
+ chain.add MyMiddleware
19
+ end
20
+ end
21
+
22
+ def perform(items)
23
+ puts "executing........."
24
+ exec_time = rand(80..200)
25
+ sleep (exec_time.to_f / 1000.to_f)
26
+ end
27
+ end
@@ -9,18 +9,23 @@ module Upperkut
9
9
 
10
10
  def execute
11
11
  worker_instance = @worker.new
12
- items = @worker.fetch_items.collect! do |item|
12
+ items = @worker.fetch_items.freeze
13
+
14
+ items_body = items.collect do |item|
13
15
  item['body']
14
16
  end
15
17
 
16
- worker_instance.perform(items.dup)
18
+ @worker.middlewares.invoke(@worker, items) do
19
+ worker_instance.perform(items_body.dup)
20
+ end
21
+
17
22
  rescue Exception => ex
18
- @worker.push_items(items)
23
+ @worker.push_items(items_body)
19
24
 
20
25
  @logger.info(
21
26
  action: :requeue,
22
27
  ex: ex,
23
- item_size: items.size
28
+ item_size: items_body.size
24
29
  )
25
30
 
26
31
  raise ex
@@ -0,0 +1,34 @@
1
+ module Upperkut
2
+ module Middleware
3
+ class Chain
4
+ attr_reader :items
5
+
6
+ def initialize
7
+ @items = []
8
+ end
9
+
10
+ def add(item)
11
+ return @items if @items.include?(item)
12
+ @items << item
13
+ end
14
+
15
+ def remove(item)
16
+ @items.delete(item)
17
+ end
18
+
19
+ def invoke(*args)
20
+ chain = @items.map(&:new)
21
+
22
+ traverse_chain = lambda do
23
+ if chain.empty?
24
+ yield
25
+ else
26
+ chain.shift.call(*args, &traverse_chain)
27
+ end
28
+ end
29
+
30
+ traverse_chain.call
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,23 @@
1
+ module Upperkut
2
+ module Middlewares
3
+ class NewRelic
4
+ include ::NewRelic::Agent::Instrumentation::ControllerInstrumentation
5
+
6
+ def call(worker, _items)
7
+ perform_action_with_newrelic_trace(trace_args(worker)) do
8
+ yield
9
+ end
10
+ end
11
+
12
+ private
13
+
14
+ def trace_args(worker)
15
+ {
16
+ 'name' => 'perform',
17
+ 'class_name' => worker.class.name,
18
+ 'category' => 'OtherTransaction/UpperkutWorker'
19
+ }
20
+ end
21
+ end
22
+ end
23
+ end
@@ -1,3 +1,3 @@
1
1
  module Upperkut
2
- VERSION = '0.3.0'.freeze
2
+ VERSION = '0.4.0'.freeze
3
3
  end
@@ -1,5 +1,6 @@
1
1
  require 'forwardable'
2
2
  require_relative 'strategy'
3
+ require_relative 'middleware'
3
4
  require_relative './util'
4
5
  require_relative '../upperkut'
5
6
 
@@ -12,7 +13,7 @@ module Upperkut
12
13
  module ClassMethods
13
14
  extend Forwardable
14
15
 
15
- def_delegators :setup, :strategy
16
+ def_delegators :setup, :strategy, :middlewares
16
17
  def_delegators :strategy, :push_items, :size, :latency, :clear
17
18
 
18
19
  def push_items(items)
data/lib/upperkut.rb CHANGED
@@ -61,6 +61,26 @@ module Upperkut
61
61
  config.polling_interval = Integer(ENV['UPPERKUT_POLLING_INTERVAL'] || 5)
62
62
  end
63
63
  end
64
+
65
+ def middlewares
66
+ @middlewares ||= init_middleware_chain
67
+ yield @middlewares if block_given?
68
+ @middlewares
69
+ end
70
+
71
+ private
72
+
73
+ def init_middleware_chain
74
+ chain = Middleware::Chain.new
75
+ if defined?(NewRelic::Agent)
76
+ require_relative 'upperkut/middlewares/new_relic'
77
+
78
+ chain.add(Upperkut::Middlewares::NewRelic)
79
+ end
80
+
81
+ chain
82
+ end
83
+
64
84
  end
65
85
 
66
86
  # Error class responsible to signal the shutdown process
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: upperkut
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nando Sousa
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-06-28 00:00:00.000000000 Z
11
+ date: 2018-07-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis
@@ -80,9 +80,9 @@ executables:
80
80
  extensions: []
81
81
  extra_rdoc_files: []
82
82
  files:
83
+ - ".circleci/config.yml"
83
84
  - ".gitignore"
84
85
  - ".rspec"
85
- - ".travis.yml"
86
86
  - CODE_OF_CONDUCT.md
87
87
  - Gemfile
88
88
  - Gemfile.lock
@@ -91,12 +91,15 @@ files:
91
91
  - Rakefile
92
92
  - bin/upperkut
93
93
  - examples/basic.rb
94
+ - examples/with_middlewares.rb
94
95
  - lib/upperkut.rb
95
96
  - lib/upperkut/batch_execution.rb
96
97
  - lib/upperkut/cli.rb
97
98
  - lib/upperkut/core_ext.rb
98
99
  - lib/upperkut/logging.rb
99
100
  - lib/upperkut/manager.rb
101
+ - lib/upperkut/middleware.rb
102
+ - lib/upperkut/middlewares/new_relic.rb
100
103
  - lib/upperkut/processor.rb
101
104
  - lib/upperkut/strategy.rb
102
105
  - lib/upperkut/util.rb
data/.travis.yml DELETED
@@ -1,5 +0,0 @@
1
- sudo: false
2
- language: ruby
3
- rvm:
4
- - 2.4.1
5
- before_install: gem install bundler -v 1.16.1