worker-glass 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +22 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +6 -0
- data/CHANGELOG.md +28 -0
- data/Gemfile +7 -0
- data/Gemfile.lock +208 -0
- data/MIT-LICENCE +18 -0
- data/README.md +94 -0
- data/Rakefile +18 -0
- data/lib/worker_glass/errors.rb +11 -0
- data/lib/worker_glass/reentrancy.rb +28 -0
- data/lib/worker_glass/timeout.rb +29 -0
- data/lib/worker_glass/version.rb +5 -0
- data/lib/worker_glass.rb +25 -0
- data/worker-glass.gemspec +23 -0
- metadata +92 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f20197a329197164ab1cbd91a21d25180a871cc8
|
4
|
+
data.tar.gz: 56dbd94122c19db5ed9b2d90e16d102dc55324e9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e943604a60634a4c019043599e7d7b502cb9525add70048417d7e2dd2fe562fa1f84dc3f942b4b13d8b0d1223dd76df79939606adf5407ba068327f67ed9f6c6
|
7
|
+
data.tar.gz: e7aaa1fcaafe67f09a06c4bef79fdb258d5c61efa675369cd5858d0f7b9e4ecc9d28add7ab73d31be3c06aefe194f3d904783c58177dd8a413785474a4c6ccd4
|
data/.gitignore
ADDED
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
worker_glass
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.2.3
|
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# WorkerGlass changelog
|
2
|
+
|
3
|
+
## 0.2.0
|
4
|
+
- Renamed from SidekiqGlass to WorkerGlass because if now does not require Sidekiq anymore to work. It will provide additional worker functionalities to any type of backend processing layer as long as it has a #perform method.
|
5
|
+
- Switched to Mongoid like feature providing by including/prepending functionalities
|
6
|
+
- WorkerGlass no longer required
|
7
|
+
- WorkerGlass::Timeout
|
8
|
+
- WorkerGlass::Reentrancy
|
9
|
+
|
10
|
+
## 0.1.4
|
11
|
+
|
12
|
+
- New Sidekiq (4.0.1) version dump
|
13
|
+
|
14
|
+
## 0.1.3
|
15
|
+
|
16
|
+
- Added null-logger gem
|
17
|
+
|
18
|
+
## 0.1.2
|
19
|
+
|
20
|
+
- SidekiqGlass logger implementation
|
21
|
+
|
22
|
+
## 0.1.1
|
23
|
+
|
24
|
+
- Celluloid lock due to some Celluloid internal issues
|
25
|
+
|
26
|
+
## 0.1.0
|
27
|
+
|
28
|
+
- Initial released version
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,208 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
worker-glass (0.2.0)
|
5
|
+
activesupport
|
6
|
+
null-logger
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
abstract_type (0.0.7)
|
12
|
+
activemodel (4.2.5)
|
13
|
+
activesupport (= 4.2.5)
|
14
|
+
builder (~> 3.1)
|
15
|
+
activesupport (4.2.5)
|
16
|
+
i18n (~> 0.7)
|
17
|
+
json (~> 1.7, >= 1.7.7)
|
18
|
+
minitest (~> 5.1)
|
19
|
+
thread_safe (~> 0.3, >= 0.3.4)
|
20
|
+
tzinfo (~> 1.1)
|
21
|
+
adamantium (0.2.0)
|
22
|
+
ice_nine (~> 0.11.0)
|
23
|
+
memoizable (~> 0.4.0)
|
24
|
+
ast (2.1.0)
|
25
|
+
astrolabe (1.3.1)
|
26
|
+
parser (~> 2.2)
|
27
|
+
axiom-types (0.1.1)
|
28
|
+
descendants_tracker (~> 0.0.4)
|
29
|
+
ice_nine (~> 0.11.0)
|
30
|
+
thread_safe (~> 0.3, >= 0.3.1)
|
31
|
+
brakeman (3.1.3)
|
32
|
+
erubis (~> 2.6)
|
33
|
+
fastercsv (~> 1.5)
|
34
|
+
haml (>= 3.0, < 5.0)
|
35
|
+
highline (>= 1.6.20, < 2.0)
|
36
|
+
multi_json (~> 1.2)
|
37
|
+
ruby2ruby (>= 2.1.1, < 2.3.0)
|
38
|
+
ruby_parser (~> 3.7.0)
|
39
|
+
safe_yaml (>= 1.0)
|
40
|
+
sass (~> 3.0)
|
41
|
+
slim (>= 1.3.6, < 4.0)
|
42
|
+
terminal-table (~> 1.4)
|
43
|
+
bson (4.0.0)
|
44
|
+
builder (3.2.2)
|
45
|
+
codeclimate-engine-rb (0.1.0)
|
46
|
+
virtus (~> 1.0)
|
47
|
+
coderay (1.1.0)
|
48
|
+
coercible (1.0.0)
|
49
|
+
descendants_tracker (~> 0.0.1)
|
50
|
+
concord (0.1.5)
|
51
|
+
adamantium (~> 0.2.0)
|
52
|
+
equalizer (~> 0.0.9)
|
53
|
+
descendants_tracker (0.0.4)
|
54
|
+
thread_safe (~> 0.3, >= 0.3.1)
|
55
|
+
diff-lcs (1.2.5)
|
56
|
+
docile (1.1.5)
|
57
|
+
equalizer (0.0.11)
|
58
|
+
erubis (2.7.0)
|
59
|
+
faker (1.6.1)
|
60
|
+
i18n (~> 0.5)
|
61
|
+
fastercsv (1.5.5)
|
62
|
+
flay (2.6.1)
|
63
|
+
ruby_parser (~> 3.0)
|
64
|
+
sexp_processor (~> 4.0)
|
65
|
+
flog (4.3.2)
|
66
|
+
ruby_parser (~> 3.1, > 3.1.0)
|
67
|
+
sexp_processor (~> 4.4)
|
68
|
+
haml (4.0.7)
|
69
|
+
tilt
|
70
|
+
haml-lint (0.13.0)
|
71
|
+
haml (~> 4.0)
|
72
|
+
rubocop (>= 0.25.0)
|
73
|
+
sysexits (~> 1.1)
|
74
|
+
highline (1.7.8)
|
75
|
+
i18n (0.7.0)
|
76
|
+
ice_nine (0.11.1)
|
77
|
+
json (1.8.3)
|
78
|
+
memoizable (0.4.2)
|
79
|
+
thread_safe (~> 0.3, >= 0.3.1)
|
80
|
+
method_source (0.8.2)
|
81
|
+
minitest (5.8.3)
|
82
|
+
mongo (2.2.1)
|
83
|
+
bson (~> 4.0)
|
84
|
+
mongoid (5.0.1)
|
85
|
+
activemodel (~> 4.0)
|
86
|
+
mongo (~> 2.1)
|
87
|
+
origin (~> 2.1)
|
88
|
+
tzinfo (>= 0.3.37)
|
89
|
+
mongoid-rspec (3.0.0)
|
90
|
+
mongoid (~> 5.0)
|
91
|
+
rake
|
92
|
+
rspec (~> 3.3)
|
93
|
+
multi_json (1.11.2)
|
94
|
+
null-logger (0.1.0)
|
95
|
+
origin (2.1.1)
|
96
|
+
parser (2.2.3.0)
|
97
|
+
ast (>= 1.1, < 3.0)
|
98
|
+
polishgeeks-dev-tools (1.2.1)
|
99
|
+
brakeman
|
100
|
+
faker
|
101
|
+
haml-lint
|
102
|
+
mongoid-rspec
|
103
|
+
pry
|
104
|
+
rspec
|
105
|
+
rubocop
|
106
|
+
rubycritic
|
107
|
+
shoulda
|
108
|
+
simplecov
|
109
|
+
timecop
|
110
|
+
yard
|
111
|
+
powerpack (0.1.1)
|
112
|
+
private_attr (1.1.0)
|
113
|
+
procto (0.0.2)
|
114
|
+
pry (0.10.3)
|
115
|
+
coderay (~> 1.1.0)
|
116
|
+
method_source (~> 0.8.1)
|
117
|
+
slop (~> 3.4)
|
118
|
+
rainbow (2.0.0)
|
119
|
+
rake (10.4.2)
|
120
|
+
reek (3.7.1)
|
121
|
+
codeclimate-engine-rb (~> 0.1.0)
|
122
|
+
parser (~> 2.2, >= 2.2.2.5)
|
123
|
+
private_attr (~> 1.1)
|
124
|
+
rainbow (~> 2.0)
|
125
|
+
unparser (~> 0.2.2)
|
126
|
+
rspec (3.4.0)
|
127
|
+
rspec-core (~> 3.4.0)
|
128
|
+
rspec-expectations (~> 3.4.0)
|
129
|
+
rspec-mocks (~> 3.4.0)
|
130
|
+
rspec-core (3.4.1)
|
131
|
+
rspec-support (~> 3.4.0)
|
132
|
+
rspec-expectations (3.4.0)
|
133
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
134
|
+
rspec-support (~> 3.4.0)
|
135
|
+
rspec-mocks (3.4.0)
|
136
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
137
|
+
rspec-support (~> 3.4.0)
|
138
|
+
rspec-support (3.4.1)
|
139
|
+
rubocop (0.35.1)
|
140
|
+
astrolabe (~> 1.3)
|
141
|
+
parser (>= 2.2.3.0, < 3.0)
|
142
|
+
powerpack (~> 0.1)
|
143
|
+
rainbow (>= 1.99.1, < 3.0)
|
144
|
+
ruby-progressbar (~> 1.7)
|
145
|
+
tins (<= 1.6.0)
|
146
|
+
ruby-progressbar (1.7.5)
|
147
|
+
ruby2ruby (2.2.0)
|
148
|
+
ruby_parser (~> 3.1)
|
149
|
+
sexp_processor (~> 4.0)
|
150
|
+
ruby_parser (3.7.2)
|
151
|
+
sexp_processor (~> 4.1)
|
152
|
+
rubycritic (2.3.0)
|
153
|
+
flay (= 2.6.1)
|
154
|
+
flog (= 4.3.2)
|
155
|
+
parser (>= 2.2.0, < 3.0)
|
156
|
+
reek (= 3.7.1)
|
157
|
+
virtus (~> 1.0)
|
158
|
+
safe_yaml (1.0.4)
|
159
|
+
sass (3.4.20)
|
160
|
+
sexp_processor (4.6.0)
|
161
|
+
shoulda (3.5.0)
|
162
|
+
shoulda-context (~> 1.0, >= 1.0.1)
|
163
|
+
shoulda-matchers (>= 1.4.1, < 3.0)
|
164
|
+
shoulda-context (1.2.1)
|
165
|
+
shoulda-matchers (2.8.0)
|
166
|
+
activesupport (>= 3.0.0)
|
167
|
+
simplecov (0.11.1)
|
168
|
+
docile (~> 1.1.0)
|
169
|
+
json (~> 1.8)
|
170
|
+
simplecov-html (~> 0.10.0)
|
171
|
+
simplecov-html (0.10.0)
|
172
|
+
slim (3.0.6)
|
173
|
+
temple (~> 0.7.3)
|
174
|
+
tilt (>= 1.3.3, < 2.1)
|
175
|
+
slop (3.6.0)
|
176
|
+
sysexits (1.2.0)
|
177
|
+
temple (0.7.6)
|
178
|
+
terminal-table (1.5.2)
|
179
|
+
thread_safe (0.3.5)
|
180
|
+
tilt (2.0.1)
|
181
|
+
timecop (0.8.0)
|
182
|
+
tins (1.6.0)
|
183
|
+
tzinfo (1.2.2)
|
184
|
+
thread_safe (~> 0.1)
|
185
|
+
unparser (0.2.4)
|
186
|
+
abstract_type (~> 0.0.7)
|
187
|
+
adamantium (~> 0.2.0)
|
188
|
+
concord (~> 0.1.5)
|
189
|
+
diff-lcs (~> 1.2.5)
|
190
|
+
equalizer (~> 0.0.9)
|
191
|
+
parser (~> 2.2.2)
|
192
|
+
procto (~> 0.0.2)
|
193
|
+
virtus (1.0.5)
|
194
|
+
axiom-types (~> 0.1)
|
195
|
+
coercible (~> 1.0)
|
196
|
+
descendants_tracker (~> 0.0, >= 0.0.3)
|
197
|
+
equalizer (~> 0.0, >= 0.0.9)
|
198
|
+
yard (0.8.7.6)
|
199
|
+
|
200
|
+
PLATFORMS
|
201
|
+
ruby
|
202
|
+
|
203
|
+
DEPENDENCIES
|
204
|
+
polishgeeks-dev-tools
|
205
|
+
worker-glass!
|
206
|
+
|
207
|
+
BUNDLED WITH
|
208
|
+
1.10.6
|
data/MIT-LICENCE
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
2
|
+
a copy of this software and associated documentation files (the
|
3
|
+
"Software"), to deal in the Software without restriction, including
|
4
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
5
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
6
|
+
permit persons to whom the Software is furnished to do so, subject to
|
7
|
+
the following conditions:
|
8
|
+
|
9
|
+
The above copyright notice and this permission notice shall be
|
10
|
+
included in all copies or substantial portions of the Software.
|
11
|
+
|
12
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
13
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
14
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
15
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
16
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
17
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
18
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
# Worker Glass
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/karafka/worker-glass.svg?branch=master)](https://travis-ci.org/karafka/worker-glass) [![Code Climate](https://codeclimate.com/github/karafka/worker-glass/badges/gpa.svg)](https://codeclimate.com/github/karafka/worker-glass)
|
4
|
+
[![Gem Version](https://badge.fury.io/rb/worker-glass.svg)](http://badge.fury.io/rb/worker-glass)
|
5
|
+
|
6
|
+
WorkerGlass provides optional timeout and after failure (reentrancy) for background processing worker engines (like Sidekiq, Resque, etc).
|
7
|
+
|
8
|
+
## Reentrancy
|
9
|
+
|
10
|
+
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/).
|
11
|
+
|
12
|
+
## Setup
|
13
|
+
|
14
|
+
If you want to use timeout and/or reentrancy, please add appropriate modules into your worker.
|
15
|
+
|
16
|
+
WorkerGlass allows to configure following options:
|
17
|
+
|
18
|
+
| Method | Arguments | Description |
|
19
|
+
|------------------|-----------|------------------------------------------------------------------------------------------|
|
20
|
+
| self.logger= | Logger | Set logger which will be used by Worker Glass (if not defined, null logger will be used) |
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
WorkerGlass has few submodules that you can prepend to your workers to obtain given functionalities:
|
25
|
+
|
26
|
+
| Module | Description |
|
27
|
+
|-------------------------|-------------------------------------------------------------------|
|
28
|
+
| WorkerGlass::Reentrancy | Provides additional reentrancy layer if anything goes wrong |
|
29
|
+
| WorkerGlass::Timeout | Allows to set a timeout after which a given worker task will fail |
|
30
|
+
|
31
|
+
|
32
|
+
### WorkerGlass::Timeout
|
33
|
+
|
34
|
+
If you want to provide timeouts for your workers, just prepend WorkerGlass::Timeout to your worker and set the timeout value:
|
35
|
+
|
36
|
+
```ruby
|
37
|
+
class Worker2 < WorkerGlass::Worker
|
38
|
+
prepend WorkerGlass::Timeout
|
39
|
+
|
40
|
+
self.timeout = 60 # 1 minute timeout
|
41
|
+
|
42
|
+
def perform(first_param, second_param, third_param)
|
43
|
+
SomeService.new.process(first_param, second_param, third_param)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
Worker2.perform_async(example1, example2, example3)
|
48
|
+
```
|
49
|
+
|
50
|
+
### WorkerGlass::Reentrancy
|
51
|
+
|
52
|
+
If you want to provide reentrancy for your workers, just include WorkerGlass::Reentrancy to your worker and define **after_failure** method that will be executed uppon failure:
|
53
|
+
|
54
|
+
```ruby
|
55
|
+
class Worker3 < WorkerGlass::Worker
|
56
|
+
include WorkerGlass::Reentrancy
|
57
|
+
|
58
|
+
def perform(first_param, second_param, third_param)
|
59
|
+
SomeService.new.process(first_param, second_param, third_param)
|
60
|
+
end
|
61
|
+
|
62
|
+
def after_failure(first_param, second_param, third_param)
|
63
|
+
SomeService.new.reset_state(first_param, second_param, third_param)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
Worker3.perform_async(example1, example2, example3)
|
68
|
+
```
|
69
|
+
|
70
|
+
## References
|
71
|
+
|
72
|
+
* [Sidekiq](http://sidekiq.org/)
|
73
|
+
* [Karafka framework](https://github.com/karafka/karafka)
|
74
|
+
* [Waterdrop](https://github.com/karafka/waterdrop)
|
75
|
+
* [Worker Glass](https://github.com/karafka/worker-glass)
|
76
|
+
* [Envlogic](https://github.com/karafka/envlogic)
|
77
|
+
* [Null Logger](https://github.com/karafka/null-logger)
|
78
|
+
* [Worker Glass Travis CI](https://travis-ci.org/karafka/worker-glass)
|
79
|
+
* [Worker Glass Code Climate](https://codeclimate.com/github/karafka/worker-glass)
|
80
|
+
|
81
|
+
## Note on Patches/Pull Requests
|
82
|
+
|
83
|
+
Fork the project.
|
84
|
+
Make your feature addition or bug fix.
|
85
|
+
Add tests for it. This is important so I don't break it in a future version unintentionally.
|
86
|
+
Commit, do not mess with Rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull). Send me a pull request. Bonus points for topic branches.
|
87
|
+
|
88
|
+
Each pull request must pass our quality requirements. To check if everything is as it should be, we use [PolishGeeks Dev Tools](https://github.com/polishgeeks/polishgeeks-dev-tools) that combine multiple linters and code analyzers. Please run:
|
89
|
+
|
90
|
+
```bash
|
91
|
+
bundle exec rake
|
92
|
+
```
|
93
|
+
|
94
|
+
to check if everything is in order. After that you can submit a pull request.
|
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,11 @@
|
|
1
|
+
module WorkerGlass
|
2
|
+
# Module enclosing all the errors that might be raised from this library
|
3
|
+
module Errors
|
4
|
+
# Base class for all the WorkerGlass internal errors
|
5
|
+
class BaseError < StandardError; end
|
6
|
+
# Raised when we use Timeout feature and timeout occurs
|
7
|
+
class TimeoutError < BaseError; end
|
8
|
+
# Raised when we use Timeout feature but we don't specify default timeout
|
9
|
+
class TimeoutNotDefined < BaseError; end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module WorkerGlass
|
2
|
+
# This module provides a reentrancy functionality for background processing engine
|
3
|
+
# @note If will reraise a given error - it does not silence them
|
4
|
+
# @example Example usage with Sidekiq - if something fails, after_failure will be executed
|
5
|
+
# class Worker
|
6
|
+
# include Sidekiq::Worker
|
7
|
+
# prepend WorkerGlass::Reentrancy
|
8
|
+
#
|
9
|
+
# def perform(*args)
|
10
|
+
# FailingService.new.run(*args)
|
11
|
+
# end
|
12
|
+
#
|
13
|
+
# def after_failure(*args)
|
14
|
+
# FailingService.new.reset(*args)
|
15
|
+
# end
|
16
|
+
# end
|
17
|
+
module Reentrancy
|
18
|
+
# Executes a business logic with additional timeouts
|
19
|
+
# @param args Any arguments that we passed when scheduling a background job
|
20
|
+
def perform(*args)
|
21
|
+
super
|
22
|
+
rescue => exception
|
23
|
+
WorkerGlass.logger.fatal(exception)
|
24
|
+
after_failure(*args)
|
25
|
+
raise exception
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module WorkerGlass
|
2
|
+
# This module provides additional timeout functionality for background processing engine
|
3
|
+
# @example Example usage with Sidekiq - will fail with timeout error after 10 seconds
|
4
|
+
# class Worker
|
5
|
+
# include Sidekiq::Worker
|
6
|
+
# prepend WorkerGlass::Timeout
|
7
|
+
#
|
8
|
+
# self.timeout = 10
|
9
|
+
#
|
10
|
+
# def perform(*args)
|
11
|
+
# SlowService.new.run(*args)
|
12
|
+
# end
|
13
|
+
# end
|
14
|
+
module Timeout
|
15
|
+
# Adds a timeout class attribute to prepended class
|
16
|
+
# @param base [Class] base class to which we prepend this module
|
17
|
+
def self.prepended(base)
|
18
|
+
base.class_attribute :timeout
|
19
|
+
end
|
20
|
+
|
21
|
+
# Executes a business logic with additional timeouts
|
22
|
+
# @param args Any arguments that we passed when scheduling a background job
|
23
|
+
# @raise [WorkerGlass::Errors::TimeoutNotDefined] if we didn't define timeout
|
24
|
+
def perform(*args)
|
25
|
+
fail Errors::TimeoutNotDefined unless self.class.timeout
|
26
|
+
::Timeout.timeout(self.class.timeout, Errors::TimeoutError) { super }
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/worker_glass.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
%w(
|
2
|
+
null_logger
|
3
|
+
active_support/core_ext/class/attribute
|
4
|
+
).each { |lib| require lib }
|
5
|
+
|
6
|
+
base_path = File.dirname(__FILE__) + '/worker_glass'
|
7
|
+
|
8
|
+
%w(
|
9
|
+
version
|
10
|
+
errors
|
11
|
+
timeout
|
12
|
+
reentrancy
|
13
|
+
).each { |lib| require File.join(base_path, lib) }
|
14
|
+
|
15
|
+
# Background worker wrappers that provides optional timeout and after failure (reentrancy)
|
16
|
+
module WorkerGlass
|
17
|
+
class << self
|
18
|
+
attr_writer :logger
|
19
|
+
|
20
|
+
# @return [Logger] logger that we want to use
|
21
|
+
def logger
|
22
|
+
@logger ||= NullLogger.new
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'rake'
|
4
|
+
require 'worker_glass/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "worker-glass"
|
8
|
+
spec.version = WorkerGlass::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
|
+
spec.summary = 'Timeout and Reentrancy for your background processing workers!'
|
13
|
+
spec.description = 'Background worker wrappers that provides optional timeout and after failure (reentrancy)'
|
14
|
+
spec.homepage = 'https://github.com/karafka/worker-glass'
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
spec.add_dependency 'null-logger'
|
18
|
+
spec.add_dependency 'activesupport'
|
19
|
+
|
20
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(spec)/}) }
|
21
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = %w( lib )
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: worker-glass
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Maciej Mensfeld
|
8
|
+
- Pavlo Vavruk
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2015-12-17 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: null-logger
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ">="
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '0'
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '0'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: activesupport
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
description: Background worker wrappers that provides optional timeout and after failure
|
43
|
+
(reentrancy)
|
44
|
+
email:
|
45
|
+
- maciej@mensfeld.pl
|
46
|
+
- pavlo.vavruk@gmail.com
|
47
|
+
executables: []
|
48
|
+
extensions: []
|
49
|
+
extra_rdoc_files: []
|
50
|
+
files:
|
51
|
+
- ".gitignore"
|
52
|
+
- ".ruby-gemset"
|
53
|
+
- ".ruby-version"
|
54
|
+
- ".travis.yml"
|
55
|
+
- CHANGELOG.md
|
56
|
+
- Gemfile
|
57
|
+
- Gemfile.lock
|
58
|
+
- MIT-LICENCE
|
59
|
+
- README.md
|
60
|
+
- Rakefile
|
61
|
+
- lib/worker_glass.rb
|
62
|
+
- lib/worker_glass/errors.rb
|
63
|
+
- lib/worker_glass/reentrancy.rb
|
64
|
+
- lib/worker_glass/timeout.rb
|
65
|
+
- lib/worker_glass/version.rb
|
66
|
+
- worker-glass.gemspec
|
67
|
+
homepage: https://github.com/karafka/worker-glass
|
68
|
+
licenses:
|
69
|
+
- MIT
|
70
|
+
metadata: {}
|
71
|
+
post_install_message:
|
72
|
+
rdoc_options: []
|
73
|
+
require_paths:
|
74
|
+
- lib
|
75
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0'
|
80
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
requirements: []
|
86
|
+
rubyforge_project:
|
87
|
+
rubygems_version: 2.4.8
|
88
|
+
signing_key:
|
89
|
+
specification_version: 4
|
90
|
+
summary: Timeout and Reentrancy for your background processing workers!
|
91
|
+
test_files: []
|
92
|
+
has_rdoc:
|