sidekiq-glass 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 96f70026aa4ae013f1f265fab9d7c16300b9ecaf
4
+ data.tar.gz: b3620f7ee2035edc7b37147da00074161f968eee
5
+ SHA512:
6
+ metadata.gz: d4d33e313fc5b06a027c8a3a5243223809d1b23c722a3348b9166b5f3bfe1003f9b4ba98ebca3e571993bc05427c6e4188a599d5834a30e6db384ceb059068dc
7
+ data.tar.gz: a39226e4845b8cfe3e5b2e0c351d46c08ddaaeb11d41eb6867e457c83692cb761c349f4332e4f92453b8a733a462f9f47efce305763bf9548a503dfcbde0aa06
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .idea
6
+ .yardoc
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ sidekiq_glass
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.2.2
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.5
4
+ - 2.2.2
5
+ script:
6
+ - bundle exec rake
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ gem 'sidekiq', '3.4.1'
6
+
7
+ group :development, :test do
8
+ gem 'polishgeeks-dev-tools', github: 'polishgeeks/polishgeeks-dev-tools'
9
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,214 @@
1
+ GIT
2
+ remote: git://github.com/polishgeeks/polishgeeks-dev-tools.git
3
+ revision: 6799827c21bb2e066a7f6be28f66d413ff60c69b
4
+ specs:
5
+ polishgeeks-dev-tools (1.0.0)
6
+ brakeman
7
+ faker
8
+ haml-lint
9
+ mongoid-rspec
10
+ pry
11
+ rspec
12
+ rubocop
13
+ rubycritic (= 1.2.1)
14
+ shoulda
15
+ simplecov
16
+ timecop
17
+ yard
18
+
19
+ PATH
20
+ remote: .
21
+ specs:
22
+ sidekiq-glass (0.1.0)
23
+ sidekiq (= 3.4.1)
24
+
25
+ GEM
26
+ remote: https://rubygems.org/
27
+ specs:
28
+ abstract_type (0.0.7)
29
+ activemodel (4.2.3)
30
+ activesupport (= 4.2.3)
31
+ builder (~> 3.1)
32
+ activesupport (4.2.3)
33
+ i18n (~> 0.7)
34
+ json (~> 1.7, >= 1.7.7)
35
+ minitest (~> 5.1)
36
+ thread_safe (~> 0.3, >= 0.3.4)
37
+ tzinfo (~> 1.1)
38
+ adamantium (0.2.0)
39
+ ice_nine (~> 0.11.0)
40
+ memoizable (~> 0.4.0)
41
+ ast (2.1.0)
42
+ astrolabe (1.3.1)
43
+ parser (~> 2.2)
44
+ axiom-types (0.1.1)
45
+ descendants_tracker (~> 0.0.4)
46
+ ice_nine (~> 0.11.0)
47
+ thread_safe (~> 0.3, >= 0.3.1)
48
+ brakeman (3.0.5)
49
+ erubis (~> 2.6)
50
+ fastercsv (~> 1.5)
51
+ haml (>= 3.0, < 5.0)
52
+ highline (~> 1.6.20)
53
+ multi_json (~> 1.2)
54
+ ruby2ruby (~> 2.1.1)
55
+ ruby_parser (~> 3.7.0)
56
+ sass (~> 3.0)
57
+ terminal-table (~> 1.4)
58
+ bson (3.2.1)
59
+ builder (3.2.2)
60
+ celluloid (0.16.1)
61
+ timers (~> 4.0.0)
62
+ coderay (1.1.0)
63
+ coercible (1.0.0)
64
+ descendants_tracker (~> 0.0.1)
65
+ concord (0.1.5)
66
+ adamantium (~> 0.2.0)
67
+ equalizer (~> 0.0.9)
68
+ connection_pool (2.2.0)
69
+ descendants_tracker (0.0.4)
70
+ thread_safe (~> 0.3, >= 0.3.1)
71
+ diff-lcs (1.2.5)
72
+ docile (1.1.5)
73
+ equalizer (0.0.11)
74
+ erubis (2.7.0)
75
+ faker (1.4.3)
76
+ i18n (~> 0.5)
77
+ fastercsv (1.5.5)
78
+ flay (2.4.0)
79
+ ruby_parser (~> 3.0)
80
+ sexp_processor (~> 4.0)
81
+ flog (4.2.1)
82
+ ruby_parser (~> 3.1, > 3.1.0)
83
+ sexp_processor (~> 4.4)
84
+ haml (4.0.7)
85
+ tilt
86
+ haml-lint (0.13.0)
87
+ haml (~> 4.0)
88
+ rubocop (>= 0.25.0)
89
+ sysexits (~> 1.1)
90
+ highline (1.6.21)
91
+ hitimes (1.2.2)
92
+ i18n (0.7.0)
93
+ ice_nine (0.11.1)
94
+ json (1.8.3)
95
+ memoizable (0.4.2)
96
+ thread_safe (~> 0.3, >= 0.3.1)
97
+ method_source (0.8.2)
98
+ minitest (5.8.0)
99
+ mongoid (4.0.2)
100
+ activemodel (~> 4.0)
101
+ moped (~> 2.0.0)
102
+ origin (~> 2.1)
103
+ tzinfo (>= 0.3.37)
104
+ mongoid-rspec (2.2.0)
105
+ mongoid (~> 4.0.0)
106
+ rake
107
+ rspec (~> 3.1)
108
+ moped (2.0.6)
109
+ bson (~> 3.0)
110
+ connection_pool (~> 2.0)
111
+ optionable (~> 0.2.0)
112
+ multi_json (1.11.2)
113
+ optionable (0.2.0)
114
+ origin (2.1.1)
115
+ parser (2.2.2.6)
116
+ ast (>= 1.1, < 3.0)
117
+ powerpack (0.1.1)
118
+ procto (0.0.2)
119
+ pry (0.10.1)
120
+ coderay (~> 1.1.0)
121
+ method_source (~> 0.8.1)
122
+ slop (~> 3.4)
123
+ rainbow (2.0.0)
124
+ rake (10.4.2)
125
+ redis (3.2.1)
126
+ redis-namespace (1.5.2)
127
+ redis (~> 3.0, >= 3.0.4)
128
+ reek (1.6.3)
129
+ parser (~> 2.2.0.pre.7)
130
+ rainbow (>= 1.99, < 3.0)
131
+ unparser (~> 0.2.2)
132
+ rspec (3.3.0)
133
+ rspec-core (~> 3.3.0)
134
+ rspec-expectations (~> 3.3.0)
135
+ rspec-mocks (~> 3.3.0)
136
+ rspec-core (3.3.2)
137
+ rspec-support (~> 3.3.0)
138
+ rspec-expectations (3.3.1)
139
+ diff-lcs (>= 1.2.0, < 2.0)
140
+ rspec-support (~> 3.3.0)
141
+ rspec-mocks (3.3.2)
142
+ diff-lcs (>= 1.2.0, < 2.0)
143
+ rspec-support (~> 3.3.0)
144
+ rspec-support (3.3.0)
145
+ rubocop (0.33.0)
146
+ astrolabe (~> 1.3)
147
+ parser (>= 2.2.2.5, < 3.0)
148
+ powerpack (~> 0.1)
149
+ rainbow (>= 1.99.1, < 3.0)
150
+ ruby-progressbar (~> 1.4)
151
+ ruby-progressbar (1.7.5)
152
+ ruby2ruby (2.1.4)
153
+ ruby_parser (~> 3.1)
154
+ sexp_processor (~> 4.0)
155
+ ruby_parser (3.7.1)
156
+ sexp_processor (~> 4.1)
157
+ rubycritic (1.2.1)
158
+ flay (= 2.4.0)
159
+ flog (= 4.2.1)
160
+ parser (>= 2.2.0, < 3.0)
161
+ reek (= 1.6.3)
162
+ ruby2ruby (>= 2.1.1, < 3.0)
163
+ virtus (~> 1.0)
164
+ sass (3.4.16)
165
+ sexp_processor (4.6.0)
166
+ shoulda (3.5.0)
167
+ shoulda-context (~> 1.0, >= 1.0.1)
168
+ shoulda-matchers (>= 1.4.1, < 3.0)
169
+ shoulda-context (1.2.1)
170
+ shoulda-matchers (2.8.0)
171
+ activesupport (>= 3.0.0)
172
+ sidekiq (3.4.1)
173
+ celluloid (~> 0.16.0)
174
+ connection_pool (>= 2.1.1)
175
+ json
176
+ redis (>= 3.0.6)
177
+ redis-namespace (>= 1.3.1)
178
+ simplecov (0.10.0)
179
+ docile (~> 1.1.0)
180
+ json (~> 1.8)
181
+ simplecov-html (~> 0.10.0)
182
+ simplecov-html (0.10.0)
183
+ slop (3.6.0)
184
+ sysexits (1.2.0)
185
+ terminal-table (1.5.2)
186
+ thread_safe (0.3.5)
187
+ tilt (2.0.1)
188
+ timecop (0.8.0)
189
+ timers (4.0.1)
190
+ hitimes
191
+ tzinfo (1.2.2)
192
+ thread_safe (~> 0.1)
193
+ unparser (0.2.4)
194
+ abstract_type (~> 0.0.7)
195
+ adamantium (~> 0.2.0)
196
+ concord (~> 0.1.5)
197
+ diff-lcs (~> 1.2.5)
198
+ equalizer (~> 0.0.9)
199
+ parser (~> 2.2.2)
200
+ procto (~> 0.0.2)
201
+ virtus (1.0.5)
202
+ axiom-types (~> 0.1)
203
+ coercible (~> 1.0)
204
+ descendants_tracker (~> 0.0, >= 0.0.3)
205
+ equalizer (~> 0.0, >= 0.0.9)
206
+ yard (0.8.7.6)
207
+
208
+ PLATFORMS
209
+ ruby
210
+
211
+ DEPENDENCIES
212
+ polishgeeks-dev-tools!
213
+ sidekiq (= 3.4.1)
214
+ sidekiq-glass!
data/README.md ADDED
@@ -0,0 +1,50 @@
1
+ # Sidekiq Glass
2
+
3
+ [![Build Status](https://travis-ci.org/karafka/sidekiq-glass.svg?branch=master)](https://travis-ci.org/karafka/sidekiq-glass) [![Code Climate](https://codeclimate.com/github/karafka/sidekiq-glass/badges/gpa.svg)](https://codeclimate.com/github/karafka/sidekiq-glass)
4
+
5
+ Sidekiq worker wrapper that provides optional timeout and after failure (reentrancy).
6
+
7
+ ## Reentrancy
8
+
9
+ If you don't know what is reentrancy, you can read about it [here](http://dev.mensfeld.pl/2014/05/ruby-rails-sinatra-background-processing-reentrancy-for-your-workers-is-a-must-be/).
10
+
11
+ ## Setup
12
+ When creating a worker that inherits from SidekiqGlass::Worker, the perform_async method provided by Sidekiq is overriden in order to provide
13
+ flexibility in the max number of params a background job can be created with and in the time a background job can take to finish.
14
+ For this, the following methods can be defined:
15
+
16
+ | Method | Arguments | Description |
17
+ |------------------|-----------|---------------------------------------------------------------------------------------------------------------|
18
+ | self.timeout= | Integer | Set the number of seconds that a job can take to finish (if not defined, Sidekiq timeout will be applied) |
19
+ | execute | any_args | Required method that will be invoked when calling Worker::perform_async |
20
+ | after_failure | any_args | Optional method that will be invoked if the execute method fails |
21
+
22
+ ## Usage
23
+
24
+ Once you've set the gem, you can start using the SidekiqGlass::Worker as following:
25
+
26
+ ```ruby
27
+ class Worker1 < SidekiqGlass::Worker
28
+ self.timeout = 3600 # job can run for 1 hour max
29
+
30
+ def execute(*ids)
31
+ SomeService.new.process(ids)
32
+ end
33
+
34
+ def after_failure(*ids)
35
+ SomeService.new.expire!(ids)
36
+ end
37
+ end
38
+
39
+ Worker1.perform_async('id1', 'id2', 'id3')
40
+ ```
41
+
42
+ ```ruby
43
+ class Worker2 < SidekiqGlass::Worker
44
+ def execute(first_param, second_param, third_param)
45
+ SomeService.new.process(first_param, second_param, third_param)
46
+ end
47
+ end
48
+
49
+ Worker2.perform_async(example1, example2, example3)
50
+ ```
data/Rakefile ADDED
@@ -0,0 +1,18 @@
1
+ require 'bundler'
2
+ require 'bundler/gem_tasks'
3
+ require 'rake'
4
+ require 'polishgeeks-dev-tools'
5
+
6
+ PolishGeeks::DevTools.setup do |config|
7
+ config.brakeman = false
8
+ config.haml_lint = false
9
+ end
10
+
11
+ desc 'Self check using polishgeeks-dev-tools'
12
+ task :check do
13
+ PolishGeeks::DevTools::Runner.new.execute(
14
+ PolishGeeks::DevTools::Logger.new
15
+ )
16
+ end
17
+
18
+ task default: :check
@@ -0,0 +1,7 @@
1
+ require 'sidekiq'
2
+
3
+ base_path = File.dirname(__FILE__) + '/sidekiq_glass'
4
+
5
+ %w( worker timeout version ).each do |file|
6
+ require File.join(base_path, file)
7
+ end
@@ -0,0 +1,21 @@
1
+ # Module encapsulating Reentrant specific code
2
+ module SidekiqGlass
3
+ # Timeout class
4
+ class Timeout
5
+ # Raised when timeout occurs
6
+ class TimeoutError < StandardError; end
7
+
8
+ # Executed given method and raises exception if it takes to much time
9
+ # @param [Integer] time in seconds that we allow given block to run
10
+ # @param [Block] block of code that we want to execute with timeout
11
+ # @return Value returned by block
12
+ # @raise [TimeoutError] error when method runs for too long
13
+ # @example Execute a block of code for max 5 seconds
14
+ # ::System::Timeout.perform(5) do
15
+ # # code that should run max 5 seconds
16
+ # end
17
+ def self.perform(time, &block)
18
+ ::Timeout.timeout(time, TimeoutError) { block.call }
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,5 @@
1
+ # Main wrapper
2
+ module SidekiqGlass
3
+ # Current version of SidekiqGlass gem
4
+ VERSION = '0.1.0'
5
+ end
@@ -0,0 +1,43 @@
1
+ require 'sidekiq_glass/version'
2
+
3
+ module SidekiqGlass
4
+ # Base worker class for all other workers
5
+ # @abstract Subclass can be used for all workers in app
6
+ # @note Please use the execute method instead of perform - because of the extra
7
+ # reentracy layer that has been introduced. Also if you define additional
8
+ # after_failure method you can handle any timeout (or any other) errors and ensure
9
+ # reentrancy for your workers
10
+ # @example Create a worker that will have a reentrancy for its task, that will
11
+ # run for max 15 seconds
12
+ #
13
+ # class LazyWorker < SidekiqGlass::Worker
14
+ # self.timeout = 15
15
+ #
16
+ # def execute(arg)
17
+ # # do some stuff here
18
+ # end
19
+ #
20
+ # def after_failure(arg)
21
+ # # do something if there is a timeout or any other error
22
+ # end
23
+ # end
24
+ class Worker
25
+ include Sidekiq::Worker
26
+
27
+ class << self
28
+ attr_accessor :timeout
29
+ end
30
+
31
+ # @param args Any arguments that we can get from Sidekiq
32
+ def perform(*args)
33
+ if self.class.timeout
34
+ ::SidekiqGlass::Timeout.perform(self.class.timeout) { execute(*args) }
35
+ else
36
+ execute(*args)
37
+ end
38
+ rescue => exception
39
+ after_failure(*args) if respond_to?(:after_failure)
40
+ raise exception
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,22 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'rake'
4
+ require 'sidekiq_glass/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "sidekiq-glass"
8
+ spec.version = SidekiqGlass::VERSION
9
+ spec.platform = Gem::Platform::RUBY
10
+ spec.authors = ['Maciej Mensfeld', 'Pavlo Vavruk']
11
+ spec.email = %w( maciej@mensfeld.pl pavlo.vavruk@gmail.com )
12
+
13
+ spec.summary = ''
14
+ spec.description = 'Sidekiq worker wrapper that provides optional timeout and after failure (reentrancy)'
15
+ spec.homepage = ''
16
+
17
+ spec.add_dependency 'sidekiq', '3.4.1'
18
+
19
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(spec)/}) }
20
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
21
+ spec.require_paths = %w( lib )
22
+ end
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sidekiq-glass
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Maciej Mensfeld
8
+ - Pavlo Vavruk
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2015-08-18 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: sidekiq
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - '='
19
+ - !ruby/object:Gem::Version
20
+ version: 3.4.1
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - '='
26
+ - !ruby/object:Gem::Version
27
+ version: 3.4.1
28
+ description: Sidekiq worker wrapper that provides optional timeout and after failure
29
+ (reentrancy)
30
+ email:
31
+ - maciej@mensfeld.pl
32
+ - pavlo.vavruk@gmail.com
33
+ executables: []
34
+ extensions: []
35
+ extra_rdoc_files: []
36
+ files:
37
+ - ".gitignore"
38
+ - ".ruby-gemset"
39
+ - ".ruby-version"
40
+ - ".travis.yml"
41
+ - Gemfile
42
+ - Gemfile.lock
43
+ - README.md
44
+ - Rakefile
45
+ - lib/sidekiq_glass.rb
46
+ - lib/sidekiq_glass/timeout.rb
47
+ - lib/sidekiq_glass/version.rb
48
+ - lib/sidekiq_glass/worker.rb
49
+ - sidekiq-glass.gemspec
50
+ homepage: ''
51
+ licenses: []
52
+ metadata: {}
53
+ post_install_message:
54
+ rdoc_options: []
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ requirements: []
68
+ rubyforge_project:
69
+ rubygems_version: 2.4.6
70
+ signing_key:
71
+ specification_version: 4
72
+ summary: ''
73
+ test_files: []
74
+ has_rdoc: