upperkut 1.0.3 → 1.0.4

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.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +65 -0
  3. data/.codeclimate.yml +15 -0
  4. data/.github/dependabot.yml +12 -0
  5. data/.gitignore +12 -0
  6. data/.rspec +4 -0
  7. data/.rubocop.yml +73 -0
  8. data/CHANGELOG.md +45 -0
  9. data/CODE_OF_CONDUCT.md +74 -0
  10. data/Dockerfile +7 -0
  11. data/Gemfile +11 -0
  12. data/Gemfile.lock +61 -0
  13. data/LICENSE.txt +21 -0
  14. data/Makefile +4 -0
  15. data/README.md +162 -0
  16. data/Rakefile +6 -0
  17. data/catalog-info.yaml +15 -0
  18. data/docker-compose.yml +18 -0
  19. data/examples/basic.rb +12 -0
  20. data/examples/priority_worker.rb +21 -0
  21. data/examples/scheduled_worker.rb +19 -0
  22. data/examples/with_middlewares.rb +42 -0
  23. data/lib/upperkut/cli.rb +100 -0
  24. data/lib/upperkut/core_ext.rb +18 -0
  25. data/lib/upperkut/item.rb +22 -0
  26. data/lib/upperkut/logging.rb +36 -0
  27. data/lib/upperkut/manager.rb +50 -0
  28. data/lib/upperkut/middleware.rb +35 -0
  29. data/lib/upperkut/middlewares/datadog.rb +11 -0
  30. data/lib/upperkut/middlewares/new_relic.rb +23 -0
  31. data/lib/upperkut/middlewares/rollbar.rb +25 -0
  32. data/lib/upperkut/processor.rb +64 -0
  33. data/lib/upperkut/redis_pool.rb +29 -0
  34. data/lib/upperkut/strategies/base.rb +56 -0
  35. data/lib/upperkut/strategies/buffered_queue.rb +218 -0
  36. data/lib/upperkut/strategies/priority_queue.rb +217 -0
  37. data/lib/upperkut/strategies/scheduled_queue.rb +162 -0
  38. data/lib/upperkut/util.rb +73 -0
  39. data/lib/upperkut/version.rb +3 -0
  40. data/lib/upperkut/worker.rb +42 -0
  41. data/lib/upperkut/worker_thread.rb +37 -0
  42. data/lib/upperkut.rb +103 -0
  43. data/upperkut.gemspec +29 -0
  44. metadata +44 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 731a0ea07d1228421c4c5a306f3de6217e11f2a594e25e28ebf333f85056c9cc
4
- data.tar.gz: 35680bb770644d47331488900de47a8ba1f2848d90cd8437511c1809ed15be32
3
+ metadata.gz: 961d354c22fd90d48b03c46718e3eb47aae82a0316fdac64ddd7d54c256aa04b
4
+ data.tar.gz: ee3d2b465a554d2cd3ec0b7ba8e42609cc2b57c60c971c878b0154bd75c1ba1d
5
5
  SHA512:
6
- metadata.gz: 0521a72596013f4e2333bf28e2e189df95dd36a781375a90e45f0f59ee59c39d1026d80822fceb798cf9fb929335a82019f50ffe701cbd48d8dfe89daafa0b06
7
- data.tar.gz: 3e0f9d1e0449aa4d6e70d76e9ea954b29624fca7efe549812d5aad3f76d653ef4fc787e70e371bd2c1b06a51e366fc8e0406f351cf9275fa008a948ee724e08d
6
+ metadata.gz: ec26662055db6114e55f6794116439d43268989871e47b77bdeb411ccc57d4062a0fda6a162be6fa3e93001ccd8c9cd8d935e82c49c162f9d3faa8e0618e0bf6
7
+ data.tar.gz: 1dff38c89064fe6cb9c1b94c3d4018ed71344ca95c034ec5f65129887da216f56917b35b03f507fb31a3374e05bb30006d327f759835d0ce5d90f688501b8e3c
@@ -0,0 +1,65 @@
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: cimg/ruby:3.2
10
+ environment:
11
+ CC_TEST_REPORTER_ID: 03ab83a772148a577d29d4acf438d7ebdc95c632224122d0ba8dbb291eedebe6
12
+ COVERAGE: true
13
+ REDIS_URL: redis://localhost:6379
14
+ - image: redis:5.0
15
+ steps:
16
+ - checkout
17
+
18
+ # Download and cache dependencies
19
+ - restore_cache:
20
+ keys:
21
+ - v1-dependencies-{{ checksum "Gemfile.lock" }}
22
+ # fallback to using the latest cache if no exact match is found
23
+ - v1-dependencies-
24
+
25
+ - run:
26
+ name: install dependencies
27
+ command: |
28
+ bundle install --jobs=4 --retry=3 --path vendor/bundle
29
+
30
+ - save_cache:
31
+ paths:
32
+ - ./vendor/bundle
33
+ key: v1-dependencies-{{ checksum "Gemfile.lock" }}
34
+
35
+ - run:
36
+ name: Setup Code Climate test-reporter
37
+ command: |
38
+ curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
39
+ chmod +x ./cc-test-reporter
40
+ ./cc-test-reporter before-build
41
+
42
+ # run tests!
43
+ - run:
44
+ name: run tests
45
+ command: |
46
+ mkdir /tmp/test-results
47
+ TEST_FILES="$(circleci tests glob "spec/**/*_spec.rb" | circleci tests split --split-by=timings)"
48
+
49
+ bundle exec rspec --format progress \
50
+ --format RspecJunitFormatter \
51
+ --out /tmp/test-results/rspec.xml \
52
+ --format progress \
53
+ $TEST_FILES
54
+ - run:
55
+ name: Submit coverage
56
+ command: |
57
+ ./cc-test-reporter after-build --coverage-input-type simplecov --exit-code $?
58
+
59
+ # collect reports
60
+ - store_test_results:
61
+ path: /tmp/test-results
62
+
63
+ - store_artifacts:
64
+ path: /tmp/test-results
65
+ destination: test-results
data/.codeclimate.yml ADDED
@@ -0,0 +1,15 @@
1
+ version: "2"
2
+ plugins:
3
+ brakeman:
4
+ enabled: false
5
+ eslint:
6
+ enabled: false
7
+ csslint:
8
+ enabled: false
9
+ rubocop:
10
+ enabled: true
11
+ channel: rubocop-0-63
12
+ reek:
13
+ enabled: true
14
+ bundler-audit:
15
+ enabled: true
@@ -0,0 +1,12 @@
1
+ version: 2
2
+ updates:
3
+ - package-ecosystem: bundler
4
+ directory: "/"
5
+ schedule:
6
+ interval: daily
7
+ time: "06:00"
8
+ timezone: Etc/UCT
9
+ pull-request-branch-name:
10
+ separator: "-"
11
+ open-pull-requests-limit: 10
12
+ rebase-strategy: disabled
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+ *.gem
data/.rspec ADDED
@@ -0,0 +1,4 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
4
+ --order random
data/.rubocop.yml ADDED
@@ -0,0 +1,73 @@
1
+ AllCops:
2
+ Exclude:
3
+ - 'vendor/**/*'
4
+ - 'spec/fixtures/**/*'
5
+ - 'tmp/**/*'
6
+ TargetRubyVersion: 3.2
7
+
8
+ Naming/PredicateName:
9
+ MethodDefinitionMacros:
10
+ - define_method
11
+ - define_singleton_method
12
+ - def_node_matcher
13
+ - def_node_search
14
+
15
+ Style/FrozenStringLiteralComment:
16
+ EnforcedStyle: always
17
+
18
+ Style/TrailingCommaInHashLiteral:
19
+ Enabled: false
20
+
21
+ Style/Documentation:
22
+ Enabled: false
23
+
24
+ Metrics/LineLength:
25
+ Max: 120
26
+
27
+ Metrics/MethodLength:
28
+ Max: 20
29
+
30
+ Layout/EndOfLine:
31
+ EnforcedStyle: lf
32
+
33
+ Layout/ClassStructure:
34
+ Enabled: true
35
+ Categories:
36
+ module_inclusion:
37
+ - include
38
+ - prepend
39
+ - extend
40
+ ExpectedOrder:
41
+ - module_inclusion
42
+ - constants
43
+ - public_class_methods
44
+ - initializer
45
+ - instance_methods
46
+ - protected_methods
47
+ - private_methods
48
+
49
+ Layout/TrailingWhitespace:
50
+ AllowInHeredoc: true
51
+
52
+ Lint/AmbiguousBlockAssociation:
53
+ Exclude:
54
+ - 'spec/**/*.rb'
55
+
56
+ Lint/InterpolationCheck:
57
+ Exclude:
58
+ - 'spec/**/*.rb'
59
+
60
+ Lint/UselessAccessModifier:
61
+ MethodCreatingMethods:
62
+ - 'def_matcher'
63
+ - 'def_node_matcher'
64
+
65
+ Metrics/BlockLength:
66
+ Exclude:
67
+ - 'Rakefile'
68
+ - '**/*.rake'
69
+ - 'spec/**/*.rb'
70
+
71
+ Metrics/ModuleLength:
72
+ Exclude:
73
+ - 'spec/**/*.rb'
data/CHANGELOG.md ADDED
@@ -0,0 +1,45 @@
1
+ # Upperkut changes
2
+ 0.8.x
3
+ --------
4
+ - Added exponential backoff when push_items #57
5
+ - Introducing Item to avoid losing enqueued at and report wrong latency
6
+ metrics #56 thanks to @jeangnc
7
+
8
+ 0.7.x
9
+ ---------
10
+ - Fix logging timeout message #54 by @jeanmatheussouto
11
+ - Add handle_error method #44
12
+ - Added Datahog Middleware (#42)
13
+ - Added Priority Queue (#39) thanks to @jeangnc and @jeanmatheussouto
14
+ - Added Scheduled Queue Implementation thanks to @rodrigo-araujo #38
15
+ - Added Datahog middleware #42 by @gabriel-augusto
16
+ - Added redis to CI #40 by #henrich-m
17
+ - Specs improvements #34 and #35, #37 by @gabriel-augusto
18
+ - Enable Rubocop #32 by @henrich-m
19
+ - Added codeclimate #31 by @henrich-m
20
+ - Extract Buffered Queue behavior to its own strategy #29
21
+
22
+ 0.6.x
23
+ ---------
24
+ - Set redis url when env var REDIS_URL is set thanks to @lucaskds #22
25
+ - Enable users to pass their own connection pool also thanks to @lucaskds #21
26
+ - Sets default concurrency to 1
27
+ - Creates connection pools by default;
28
+ - Simplifies API to enable extension via Strategy;
29
+
30
+ 0.5.x
31
+ ----------
32
+ - Introducing client middlewares.
33
+ - Fix issue that prevented worker to run.
34
+ - Fix thread-unsafe code that was overwriting worker configurations when
35
+ multiples workers were configured in the same process.
36
+
37
+ 0.4.x
38
+ -----------
39
+
40
+ - Change redis versioning policy #17
41
+ - Fixed error that prevented users from start upperkut from non Rails apps.
42
+ - Added integration with Rollbar.
43
+ - Added backtrace to logs when some error occurs.
44
+ - Fixed NewRelic trace args
45
+
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at nandosousafr@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Dockerfile ADDED
@@ -0,0 +1,7 @@
1
+ FROM ruby:3.2
2
+
3
+ WORKDIR /code
4
+ COPY . .
5
+
6
+ RUN gem install bundler
7
+ RUN bundle install
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source 'https://rubygems.org'
2
+
3
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in upperkut.gemspec
6
+ gemspec
7
+
8
+ gem 'fivemat'
9
+ gem 'pry'
10
+ gem 'rspec_junit_formatter'
11
+ gem 'simplecov', '< 0.23', require: false
data/Gemfile.lock ADDED
@@ -0,0 +1,61 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ upperkut (1.0.4)
5
+ connection_pool (~> 2.2, >= 2.2.2)
6
+ redis (>= 4.1.0, < 6.0.0)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ coderay (1.1.3)
12
+ connection_pool (2.3.0)
13
+ diff-lcs (1.5.0)
14
+ docile (1.4.0)
15
+ fivemat (1.3.7)
16
+ method_source (1.0.0)
17
+ pry (0.14.2)
18
+ coderay (~> 1.1)
19
+ method_source (~> 1.0)
20
+ rake (13.0.6)
21
+ redis (5.0.6)
22
+ redis-client (>= 0.9.0)
23
+ redis-client (0.12.1)
24
+ connection_pool
25
+ rspec (3.12.0)
26
+ rspec-core (~> 3.12.0)
27
+ rspec-expectations (~> 3.12.0)
28
+ rspec-mocks (~> 3.12.0)
29
+ rspec-core (3.12.1)
30
+ rspec-support (~> 3.12.0)
31
+ rspec-expectations (3.12.2)
32
+ diff-lcs (>= 1.2.0, < 2.0)
33
+ rspec-support (~> 3.12.0)
34
+ rspec-mocks (3.12.4)
35
+ diff-lcs (>= 1.2.0, < 2.0)
36
+ rspec-support (~> 3.12.0)
37
+ rspec-support (3.12.0)
38
+ rspec_junit_formatter (0.6.0)
39
+ rspec-core (>= 2, < 4, != 2.12.0)
40
+ simplecov (0.22.0)
41
+ docile (~> 1.1)
42
+ simplecov-html (~> 0.11)
43
+ simplecov_json_formatter (~> 0.1)
44
+ simplecov-html (0.12.3)
45
+ simplecov_json_formatter (0.1.4)
46
+
47
+ PLATFORMS
48
+ ruby
49
+
50
+ DEPENDENCIES
51
+ bundler (>= 1.16)
52
+ fivemat
53
+ pry
54
+ rake (~> 13.0)
55
+ rspec (~> 3.0)
56
+ rspec_junit_formatter
57
+ simplecov (< 0.23)
58
+ upperkut!
59
+
60
+ BUNDLED WITH
61
+ 2.4.1
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Nando Sousa
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/Makefile ADDED
@@ -0,0 +1,4 @@
1
+ bash:
2
+ docker-compose run gem bash
3
+ specs:
4
+ docker-compose run gem bundle exec rspec
data/README.md ADDED
@@ -0,0 +1,162 @@
1
+ # Upperkut
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
+
7
+ [[Docs]](https://www.rubydoc.info/gems/upperkut/0.7.2/Upperkut)
8
+
9
+ Background processing framework for Ruby applications.
10
+
11
+ ## Installation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ ```ruby
16
+ gem 'upperkut'
17
+ ```
18
+
19
+ And then execute:
20
+
21
+ $ bundle
22
+
23
+ Or install it yourself as:
24
+
25
+ $ gem install upperkut
26
+
27
+ ## Usage
28
+
29
+ ### Example 1 - Buffered Queue:
30
+
31
+ 1) Create a Worker class and the define how to process the batch;
32
+ ```ruby
33
+ class MyWorker
34
+ include Upperkut::Worker
35
+
36
+ def perform(batch_items)
37
+ heavy_processing(batch_items)
38
+ process_metrics(batch_items)
39
+ end
40
+ end
41
+ ```
42
+
43
+ 2) Start pushing items;
44
+ ```ruby
45
+ MyWorker.push_items(
46
+ [
47
+ {
48
+ 'id' => SecureRandom.uuid,
49
+ 'name' => 'Robert C Hall',
50
+ 'action' => 'EMAIL_OPENNED'
51
+ }
52
+ ]
53
+ )
54
+ ```
55
+
56
+ 3) Start Upperkut;
57
+ ```bash
58
+ $ bundle exec upperkut --worker MyWorker --concurrency 10
59
+ ```
60
+
61
+ ### Example 2 - Scheduled Queue:
62
+
63
+ 1) Create a Worker class and the define how to process the batch;
64
+ ```ruby
65
+ require 'upperkut/strategies/scheduled_queue'
66
+ class MyWorker
67
+ include Upperkut::Worker
68
+
69
+ setup_upperkut do |config|
70
+ config.strategy = Upperkut::Strategies::ScheduledQueue.new(self)
71
+ end
72
+
73
+ def perform(batch_items)
74
+ heavy_processing(batch_items)
75
+ process_metrics(batch_items)
76
+ end
77
+ end
78
+ ```
79
+
80
+ 2) Start pushing items with `timestamp` parameter;
81
+ ```ruby
82
+ # timestamp is 'Thu, 10 May 2019 23:43:58 GMT'
83
+ MyWorker.push_items(
84
+ [
85
+ {
86
+ 'timestamp' => '1557531838',
87
+ 'id' => SecureRandom.uuid,
88
+ 'name' => 'Robert C Hall',
89
+ 'action' => 'SEND_NOTIFICATION'
90
+ }
91
+ ]
92
+ )
93
+ ```
94
+
95
+ 3) Start Upperkut;
96
+ ```bash
97
+ $ bundle exec upperkut --worker MyWorker --concurrency 10
98
+ ```
99
+
100
+ ### Example 3 - Priority Queue:
101
+
102
+ Note: priority queues requires redis 5.0.0+ as it uses ZPOP* commands.
103
+
104
+ 1) Create a Worker class and the define how to process the batch;
105
+ ```ruby
106
+ require 'upperkut/strategies/priority_queue'
107
+
108
+ class MyWorker
109
+ include Upperkut::Worker
110
+
111
+ setup_upperkut do |config|
112
+ config.strategy = Upperkut::Strategies::PriorityQueue.new(
113
+ self,
114
+ priority_key: -> { |item| item['tenant_id'] }
115
+ )
116
+ end
117
+
118
+ def perform(items)
119
+ items.each do |item|
120
+ puts "event dispatched: #{item.inspect}"
121
+ end
122
+ end
123
+ end
124
+ ```
125
+
126
+ 2) So you can enqueue items from different tenants;
127
+ ```ruby
128
+ MyWorker.push_items(
129
+ [
130
+ { 'tenant_id' => 1, 'id' => 1 },
131
+ { 'tenant_id' => 1, 'id' => 2 },
132
+ { 'tenant_id' => 1, 'id' => 3 },
133
+ { 'tenant_id' => 2, 'id' => 4 },
134
+ { 'tenant_id' => 3, 'id' => 5 },
135
+ ]
136
+ )
137
+ ```
138
+
139
+ The code above will enqueue items as follows `1, 4, 5, 2, 3`
140
+
141
+ 3) Start Upperkut;
142
+ ```bash
143
+ $ bundle exec upperkut --worker MyWorker --concurrency 10
144
+ ```
145
+
146
+ ## Development
147
+
148
+ After checking out the repo, run `bundle install` to install dependencies. Then, run `bundle exec rspec` to run the tests.
149
+
150
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
151
+
152
+ ## Contributing
153
+
154
+ 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.
155
+
156
+ ## License
157
+
158
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
159
+
160
+ ## Code of Conduct
161
+
162
+ 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/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
data/catalog-info.yaml ADDED
@@ -0,0 +1,15 @@
1
+ apiVersion: backstage.io/v1alpha1
2
+ kind: Component
3
+ metadata:
4
+ name: upperkut
5
+ description: Ferramenta de processamento em segundo plano para Ruby.
6
+ annotations:
7
+ circleci.com/project-slug: github/ResultadosDigitais/upperkut
8
+ github.com/project-slug: ResultadosDigitais/upperkut
9
+ links:
10
+ - url: https://opensource.resultadosdigitais.com.br/
11
+ title: Projetos open source da RD.
12
+ spec:
13
+ type: library
14
+ owner: devtools
15
+ lifecycle: production
@@ -0,0 +1,18 @@
1
+ services:
2
+ gem:
3
+ build: .
4
+ volumes:
5
+ - .:/code
6
+ environment:
7
+ - REDIS_URL=redis://redis:6379
8
+ depends_on:
9
+ - redis
10
+ redis:
11
+ image: redis:5.0.4-alpine
12
+ command: redis-server --save "" --appendonly yes --appendfsync everysec
13
+ ports:
14
+ - 6379:6379
15
+ volumes:
16
+ - redis-data:/data
17
+ volumes:
18
+ redis-data:
data/examples/basic.rb ADDED
@@ -0,0 +1,12 @@
1
+ require_relative '../lib/upperkut/worker'
2
+
3
+ class MyWorker
4
+ include Upperkut::Worker
5
+
6
+ def perform(items)
7
+ puts 'starting performing'
8
+ exec_time = rand(9000..50_000)
9
+ sleep (exec_time.to_f / 1000.to_f)
10
+ puts "performed #{items.size} items in #{exec_time.to_f / 1000.to_f} ms"
11
+ end
12
+ end
@@ -0,0 +1,21 @@
1
+ require_relative '../lib/upperkut/worker'
2
+ require_relative '../lib/upperkut/strategies/priority_queue'
3
+
4
+ class PriorityWorker
5
+ include Upperkut::Worker
6
+
7
+ setup_upperkut do |config|
8
+ config.strategy = Upperkut::Strategies::PriorityQueue.new(
9
+ self,
10
+ priority_key: -> { |item| item['tenant_id'] },
11
+ batch_size: 1
12
+ )
13
+ end
14
+
15
+ def perform(items)
16
+ items.each do |item|
17
+ puts "event dispatched: #{item.inspect}"
18
+ sleep 1
19
+ end
20
+ end
21
+ end