upperkut 1.0.2 → 1.0.3

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.
@@ -1,37 +0,0 @@
1
- require_relative 'processor'
2
-
3
- module Upperkut
4
- class WorkerThread
5
- def initialize(manager, processor)
6
- @manager = manager
7
- @processor = processor
8
- end
9
-
10
- def run
11
- @thread ||= Thread.new do
12
- begin
13
- @processor.blocking_process
14
- rescue Exception => e
15
- @manager.logger.debug(
16
- action: :processor_killed,
17
- reason: e,
18
- stacktrace: e.backtrace
19
- )
20
-
21
- @manager.notify_killed_processor(self)
22
- end
23
- end
24
- end
25
-
26
- def stop
27
- @processor.stop
28
- end
29
-
30
- def kill
31
- return unless @thread
32
-
33
- @thread.raise Upperkut::Shutdown
34
- @thread.value # wait
35
- end
36
- end
37
- end
data/lib/upperkut.rb DELETED
@@ -1,103 +0,0 @@
1
- require_relative 'upperkut/version'
2
- require_relative 'upperkut/worker'
3
- require 'redis'
4
-
5
- # Public: Upperkut is a batch background processing tool for Ruby.
6
- #
7
- # Examples:
8
- #
9
- # 1) Create a Worker class and the define how to process the batch;
10
- #
11
- # class MyWorker
12
- # include Upperkut::Worker
13
- #
14
- # # This is optional
15
- #
16
- # setup_upperkut do |config|
17
- # # Define which redis instance you want to use
18
- # config.strategy = Upperkut::Strategy.new(
19
- # self,
20
- # redis: { url: ENV['ANOTHER_REDIS_URL'] }
21
- # )
22
- #
23
- # # Define the amount of items must be accumulated
24
- # config.batch_size = 2_000 # The default value is 1_000
25
- #
26
- # # How frequent the Processor should hit redis looking for elegible
27
- # # batch. The default value is 5 seconds. You can also set the env
28
- # # UPPERKUT_POLLING_INTERVAL.
29
- # config.polling_interval = 4
30
- #
31
- # # How long the Processor should wait in seconds to process batch
32
- # # even though the amount of items did not reached the batch_size.
33
- # config.max_wait = 300
34
- # end
35
- #
36
- # def perform(batch_items)
37
- # SidekiqJobA.perform_async(batch_items)
38
- # SidekiqJobB.perform_async(batch_items)
39
- #
40
- # process_metrics(batch_items)
41
- # end
42
- # end
43
- #
44
- # 2) Start pushings items;
45
- #
46
- # Myworker.push_items(
47
- # [{'id' => SecureRandom.uuid, 'name' => 'Robert C Hall', 'action' => 'EMAIL_OPENNED'}]
48
- # )
49
- #
50
- # 3) Start Upperkut;
51
- #
52
- # $ bundle exec upperkut -worker MyWorker --concurrency 10
53
- #
54
- # 4) That's it :)
55
- module Upperkut
56
- class Configuration
57
- attr_accessor :strategy, :polling_interval
58
-
59
- def self.default
60
- new.tap do |config|
61
- config.polling_interval = Float(ENV['UPPERKUT_POLLING_INTERVAL'] || 5)
62
- end
63
- end
64
-
65
- def server_middlewares
66
- @server_middlewares ||= init_middleware_chain
67
- yield @server_middlewares if block_given?
68
- @server_middlewares
69
- end
70
-
71
- def client_middlewares
72
- @client_middlewares ||= Middleware::Chain.new
73
- yield @client_middlewares if block_given?
74
- @client_middlewares
75
- end
76
-
77
- private
78
-
79
- def init_middleware_chain
80
- chain = Middleware::Chain.new
81
-
82
- if defined?(NewRelic::Agent)
83
- require_relative 'upperkut/middlewares/new_relic'
84
- chain.add(Upperkut::Middlewares::NewRelic)
85
- end
86
-
87
- if defined?(Rollbar::VERSION)
88
- require_relative 'upperkut/middlewares/rollbar'
89
- chain.add(Upperkut::Middlewares::Rollbar)
90
- end
91
-
92
- if defined?(Datadog)
93
- require_relative 'upperkut/middlewares/datadog'
94
- chain.add(Upperkut::Middlewares::Datadog)
95
- end
96
-
97
- chain
98
- end
99
- end
100
-
101
- # Error class responsible to signal the shutdown process
102
- class Shutdown < StandardError; end
103
- end
data/upperkut.gemspec DELETED
@@ -1,29 +0,0 @@
1
- lib = File.expand_path('lib', __dir__)
2
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
- require 'upperkut/version'
4
-
5
- Gem::Specification.new do |spec|
6
- spec.name = 'upperkut'
7
- spec.version = Upperkut::VERSION
8
- spec.authors = ['Nando Sousa']
9
- spec.email = ['nandosousafr@gmail.com']
10
-
11
- spec.summary = 'Batch background processing tool'
12
- spec.description = 'Batch background processing tool'
13
- spec.homepage = 'http://shipit.resultadosdigitais.com.br/open-source/'
14
- spec.license = 'MIT'
15
-
16
- spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
- f.match(%r{^(test|spec|features)/})
18
- end
19
- spec.executables = ['upperkut']
20
- spec.require_paths = ['lib']
21
-
22
- spec.required_ruby_version = '>= 2.2.2'
23
-
24
- spec.add_dependency 'connection_pool', '~> 2.2', '>= 2.2.2'
25
- spec.add_dependency 'redis', '>= 4.1.0', '< 5.0.0'
26
- spec.add_development_dependency 'bundler', '>= 1.16'
27
- spec.add_development_dependency 'rake', '~> 13.0'
28
- spec.add_development_dependency 'rspec', '~> 3.0'
29
- end