fleiss 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +4 -1
- data/.travis.yml +2 -0
- data/Gemfile.lock +24 -26
- data/bin/fleiss +4 -4
- data/fleiss.gemspec +3 -3
- data/lib/fleiss/backend/active_record/concern.rb +4 -0
- data/lib/fleiss/executor.rb +22 -0
- data/lib/fleiss/worker.rb +10 -9
- data/spec/fleiss/executor_spec.rb +28 -0
- metadata +11 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5f5d2237b3a3bb01c8998c273a9fbb4f65cbf75b737df03187db2315c1efa93d
|
4
|
+
data.tar.gz: c80f8f0423dea4b516e824ccb669ec2e34abb6c2365adbe5cea937101526c429
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e497a57b2aec4333ce4cde801a7bcf631546158c1b4c1d2b2a663ca997066438f01bb14b5103637cbb661c168e403c4b21014dbe92ee2fb927806a377b788f21
|
7
|
+
data.tar.gz: 7d18e086ebe3ca8f6d8c0c025ca302abdfa487487548c38664d18904cd5c3a8d7e1997132054af334c5cbb1e8863b01fcdf176546f7d9d300e30443a2958bbe0
|
data/.rubocop.yml
CHANGED
data/.travis.yml
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
fleiss (0.
|
4
|
+
fleiss (0.3.0)
|
5
5
|
activejob (>= 5.0)
|
6
6
|
activerecord (>= 5.0)
|
7
7
|
concurrent-ruby
|
@@ -9,36 +9,35 @@ PATH
|
|
9
9
|
GEM
|
10
10
|
remote: https://rubygems.org/
|
11
11
|
specs:
|
12
|
-
activejob (5.2.
|
13
|
-
activesupport (= 5.2.
|
12
|
+
activejob (5.2.3)
|
13
|
+
activesupport (= 5.2.3)
|
14
14
|
globalid (>= 0.3.6)
|
15
|
-
activemodel (5.2.
|
16
|
-
activesupport (= 5.2.
|
17
|
-
activerecord (5.2.
|
18
|
-
activemodel (= 5.2.
|
19
|
-
activesupport (= 5.2.
|
15
|
+
activemodel (5.2.3)
|
16
|
+
activesupport (= 5.2.3)
|
17
|
+
activerecord (5.2.3)
|
18
|
+
activemodel (= 5.2.3)
|
19
|
+
activesupport (= 5.2.3)
|
20
20
|
arel (>= 9.0)
|
21
|
-
activesupport (5.2.
|
21
|
+
activesupport (5.2.3)
|
22
22
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
23
23
|
i18n (>= 0.7, < 2)
|
24
24
|
minitest (~> 5.1)
|
25
25
|
tzinfo (~> 1.1)
|
26
26
|
arel (9.0.0)
|
27
27
|
ast (2.4.0)
|
28
|
-
concurrent-ruby (1.1.
|
28
|
+
concurrent-ruby (1.1.5)
|
29
29
|
diff-lcs (1.3)
|
30
|
-
globalid (0.4.
|
30
|
+
globalid (0.4.2)
|
31
31
|
activesupport (>= 4.2.0)
|
32
|
-
i18n (1.
|
32
|
+
i18n (1.6.0)
|
33
33
|
concurrent-ruby (~> 1.0)
|
34
|
-
jaro_winkler (1.5.
|
34
|
+
jaro_winkler (1.5.2)
|
35
35
|
minitest (5.11.3)
|
36
36
|
mysql2 (0.5.2)
|
37
|
-
parallel (1.
|
38
|
-
parser (2.
|
37
|
+
parallel (1.17.0)
|
38
|
+
parser (2.6.3.0)
|
39
39
|
ast (~> 2.4.0)
|
40
|
-
pg (1.1.
|
41
|
-
powerpack (0.1.2)
|
40
|
+
pg (1.1.4)
|
42
41
|
rainbow (3.0.0)
|
43
42
|
rake (12.3.2)
|
44
43
|
rspec (3.8.0)
|
@@ -47,27 +46,26 @@ GEM
|
|
47
46
|
rspec-mocks (~> 3.8.0)
|
48
47
|
rspec-core (3.8.0)
|
49
48
|
rspec-support (~> 3.8.0)
|
50
|
-
rspec-expectations (3.8.
|
49
|
+
rspec-expectations (3.8.3)
|
51
50
|
diff-lcs (>= 1.2.0, < 2.0)
|
52
51
|
rspec-support (~> 3.8.0)
|
53
52
|
rspec-mocks (3.8.0)
|
54
53
|
diff-lcs (>= 1.2.0, < 2.0)
|
55
54
|
rspec-support (~> 3.8.0)
|
56
55
|
rspec-support (3.8.0)
|
57
|
-
rubocop (0.
|
56
|
+
rubocop (0.71.0)
|
58
57
|
jaro_winkler (~> 1.5.1)
|
59
58
|
parallel (~> 1.10)
|
60
|
-
parser (>= 2.
|
61
|
-
powerpack (~> 0.1)
|
59
|
+
parser (>= 2.6)
|
62
60
|
rainbow (>= 2.2.2, < 4.0)
|
63
61
|
ruby-progressbar (~> 1.7)
|
64
|
-
unicode-display_width (
|
65
|
-
ruby-progressbar (1.10.
|
62
|
+
unicode-display_width (>= 1.4.0, < 1.7)
|
63
|
+
ruby-progressbar (1.10.1)
|
66
64
|
sqlite3 (1.3.13)
|
67
65
|
thread_safe (0.3.6)
|
68
66
|
tzinfo (1.2.5)
|
69
67
|
thread_safe (~> 0.1)
|
70
|
-
unicode-display_width (1.
|
68
|
+
unicode-display_width (1.6.0)
|
71
69
|
|
72
70
|
PLATFORMS
|
73
71
|
ruby
|
@@ -80,7 +78,7 @@ DEPENDENCIES
|
|
80
78
|
rake
|
81
79
|
rspec
|
82
80
|
rubocop
|
83
|
-
sqlite3
|
81
|
+
sqlite3 (~> 1.3.6)
|
84
82
|
|
85
83
|
BUNDLED WITH
|
86
|
-
|
84
|
+
2.0.1
|
data/bin/fleiss
CHANGED
@@ -13,12 +13,12 @@ begin
|
|
13
13
|
cli.parse!
|
14
14
|
cli.run!
|
15
15
|
rescue ArgumentError => e
|
16
|
-
|
16
|
+
warn " ! #{e.message}\n"
|
17
17
|
STDERR.puts
|
18
|
-
|
18
|
+
warn cli.parser
|
19
19
|
exit 1
|
20
20
|
rescue StandardError => e
|
21
|
-
|
22
|
-
|
21
|
+
warn e.message
|
22
|
+
warn e.backtrace.join("\n")
|
23
23
|
exit 1
|
24
24
|
end
|
data/fleiss.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'fleiss'
|
3
|
-
s.version = '0.
|
3
|
+
s.version = '0.3.0'
|
4
4
|
s.authors = ['Black Square Media Ltd']
|
5
5
|
s.email = ['info@blacksquaremedia.com']
|
6
6
|
s.summary = %(Minimialist background jobs backed by ActiveJob and ActiveRecord.)
|
@@ -12,7 +12,7 @@ Gem::Specification.new do |s|
|
|
12
12
|
s.files = `git ls-files -z`.split("\x0").reject {|f| f.match(%r{^spec/}) }
|
13
13
|
s.test_files = `git ls-files -z -- spec/*`.split("\x0")
|
14
14
|
s.require_paths = ['lib']
|
15
|
-
s.required_ruby_version = '>= 2.
|
15
|
+
s.required_ruby_version = '>= 2.4'
|
16
16
|
|
17
17
|
s.add_dependency 'activejob', '>= 5.0'
|
18
18
|
s.add_dependency 'activerecord', '>= 5.0'
|
@@ -24,5 +24,5 @@ Gem::Specification.new do |s|
|
|
24
24
|
s.add_development_dependency 'rake'
|
25
25
|
s.add_development_dependency 'rspec'
|
26
26
|
s.add_development_dependency 'rubocop'
|
27
|
-
s.add_development_dependency 'sqlite3'
|
27
|
+
s.add_development_dependency 'sqlite3', '~> 1.3.6'
|
28
28
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'fleiss'
|
2
|
+
require 'concurrent/executor/simple_executor_service'
|
3
|
+
|
4
|
+
class Fleiss::Executor < Concurrent::SimpleExecutorService
|
5
|
+
attr_reader :max_size
|
6
|
+
|
7
|
+
def post(&block)
|
8
|
+
super unless capacity.zero?
|
9
|
+
end
|
10
|
+
|
11
|
+
def capacity
|
12
|
+
val = @max_size - @count.value
|
13
|
+
val.positive? ? val : 0
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def ns_initialize(opts={})
|
19
|
+
super()
|
20
|
+
@max_size = opts.fetch(:max_size, 1).to_i
|
21
|
+
end
|
22
|
+
end
|
data/lib/fleiss/worker.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
require 'fleiss'
|
2
|
-
require '
|
3
|
-
require 'concurrent/atomic/atomic_fixnum'
|
2
|
+
require 'fleiss/executor'
|
4
3
|
require 'securerandom'
|
5
4
|
|
6
5
|
class Fleiss::Worker
|
@@ -20,13 +19,13 @@ class Fleiss::Worker
|
|
20
19
|
def initialize(queues: [Fleiss::DEFAULT_QUEUE], concurrency: 10, wait_time: 1)
|
21
20
|
@uuid = SecureRandom.uuid
|
22
21
|
@queues = Array(queues)
|
23
|
-
@pool =
|
22
|
+
@pool = Fleiss::Executor.new(max_size: concurrency)
|
24
23
|
@wait_time = wait_time
|
25
24
|
end
|
26
25
|
|
27
26
|
# Run starts the worker
|
28
27
|
def run
|
29
|
-
log(:info) { "Worker #{uuid} starting - queues: #{queues.inspect}, concurrency: #{@pool.
|
28
|
+
log(:info) { "Worker #{uuid} starting - queues: #{queues.inspect}, concurrency: #{@pool.max_size}" }
|
30
29
|
loop do
|
31
30
|
run_cycle
|
32
31
|
sleep @wait_time
|
@@ -50,19 +49,21 @@ class Fleiss::Worker
|
|
50
49
|
end
|
51
50
|
|
52
51
|
def run_cycle
|
53
|
-
return
|
52
|
+
return unless @pool.running?
|
54
53
|
|
55
|
-
|
56
|
-
return unless
|
54
|
+
limit = @pool.capacity
|
55
|
+
return unless limit.positive?
|
57
56
|
|
58
57
|
batch = Fleiss.backend
|
59
58
|
.in_queue(queues)
|
60
59
|
.pending
|
61
|
-
.limit(
|
60
|
+
.limit(limit)
|
62
61
|
.to_a
|
63
62
|
|
64
63
|
batch.each do |job|
|
65
|
-
@pool.post
|
64
|
+
@pool.post do
|
65
|
+
Fleiss.backend.wrap_perform { perform(job) }
|
66
|
+
end
|
66
67
|
end
|
67
68
|
rescue StandardError => e
|
68
69
|
handle_exception e, 'running cycle'
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'fleiss/executor'
|
3
|
+
|
4
|
+
RSpec.describe Fleiss::Executor do
|
5
|
+
subject { described_class.new max_size: 2 }
|
6
|
+
after { subject.kill }
|
7
|
+
|
8
|
+
it 'should check capacity' do
|
9
|
+
expect(described_class.new.capacity).to eq(1)
|
10
|
+
|
11
|
+
expect(subject.capacity).to eq(2)
|
12
|
+
subject.post { sleep(1) }
|
13
|
+
expect(subject.capacity).to eq(1)
|
14
|
+
subject.post { sleep(1) }
|
15
|
+
expect(subject.capacity).to eq(0)
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should discard execution when capacity is reached' do
|
19
|
+
n = Concurrent::AtomicFixnum.new(0)
|
20
|
+
10.times do
|
21
|
+
10.times { subject.post { n.increment } }
|
22
|
+
sleep(0.001)
|
23
|
+
end
|
24
|
+
subject.shutdown
|
25
|
+
subject.wait_for_termination(1)
|
26
|
+
expect(n.value).to be_within(10).of(20)
|
27
|
+
end
|
28
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fleiss
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Black Square Media Ltd
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-05-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activejob
|
@@ -140,16 +140,16 @@ dependencies:
|
|
140
140
|
name: sqlite3
|
141
141
|
requirement: !ruby/object:Gem::Requirement
|
142
142
|
requirements:
|
143
|
-
- - "
|
143
|
+
- - "~>"
|
144
144
|
- !ruby/object:Gem::Version
|
145
|
-
version:
|
145
|
+
version: 1.3.6
|
146
146
|
type: :development
|
147
147
|
prerelease: false
|
148
148
|
version_requirements: !ruby/object:Gem::Requirement
|
149
149
|
requirements:
|
150
|
-
- - "
|
150
|
+
- - "~>"
|
151
151
|
- !ruby/object:Gem::Version
|
152
|
-
version:
|
152
|
+
version: 1.3.6
|
153
153
|
description: Run background jobs with your favourite stack.
|
154
154
|
email:
|
155
155
|
- info@blacksquaremedia.com
|
@@ -176,8 +176,10 @@ files:
|
|
176
176
|
- lib/fleiss/backend/active_record/concern.rb
|
177
177
|
- lib/fleiss/backend/active_record/migration.rb
|
178
178
|
- lib/fleiss/cli.rb
|
179
|
+
- lib/fleiss/executor.rb
|
179
180
|
- lib/fleiss/worker.rb
|
180
181
|
- spec/fleiss/backend/active_record_spec.rb
|
182
|
+
- spec/fleiss/executor_spec.rb
|
181
183
|
- spec/fleiss/worker_spec.rb
|
182
184
|
- spec/fleiss_spec.rb
|
183
185
|
- spec/spec_helper.rb
|
@@ -193,20 +195,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
193
195
|
requirements:
|
194
196
|
- - ">="
|
195
197
|
- !ruby/object:Gem::Version
|
196
|
-
version: '2.
|
198
|
+
version: '2.4'
|
197
199
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
198
200
|
requirements:
|
199
201
|
- - ">="
|
200
202
|
- !ruby/object:Gem::Version
|
201
203
|
version: '0'
|
202
204
|
requirements: []
|
203
|
-
|
204
|
-
rubygems_version: 2.7.7
|
205
|
+
rubygems_version: 3.0.3
|
205
206
|
signing_key:
|
206
207
|
specification_version: 4
|
207
208
|
summary: Minimialist background jobs backed by ActiveJob and ActiveRecord.
|
208
209
|
test_files:
|
209
210
|
- spec/fleiss/backend/active_record_spec.rb
|
211
|
+
- spec/fleiss/executor_spec.rb
|
210
212
|
- spec/fleiss/worker_spec.rb
|
211
213
|
- spec/fleiss_spec.rb
|
212
214
|
- spec/spec_helper.rb
|