fleiss 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +6 -2
- data/Gemfile.lock +66 -46
- data/bin/fleiss +3 -3
- data/fleiss.gemspec +2 -2
- data/lib/fleiss/backend/active_record/concern.rb +9 -4
- data/lib/fleiss/backend/active_record/migration.rb +1 -1
- data/spec/fleiss/backend/active_record_spec.rb +11 -11
- data/spec/fleiss/executor_spec.rb +3 -2
- data/spec/fleiss/worker_spec.rb +2 -2
- data/spec/fleiss_spec.rb +2 -2
- data/spec/spec_helper.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3433257ea2a501706212f8876c0c9636a00028a6c9616daf86d66aa36d0dbd9a
|
4
|
+
data.tar.gz: d792288414d281a0667fd8100475eb45ec610c3330fce5e0d8434aa3d3ac50fe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0fbf7922526ece6336986a26e69bfcf84263d3183ab39bb296f82ae1b08994af912d52f7d06ab16dee5f31c1100643814e220aa2052b6ca408b459ad8efb4a8d
|
7
|
+
data.tar.gz: a23fe3139ea3f1f891847343333e476de1edc1bf35b24279122b734f2867a15b66d5da9cfa77c37820e511a97c40a240bc4e3c7ae77c721020591119f8c3652f
|
data/.rubocop.yml
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
fleiss (0.4.
|
4
|
+
fleiss (0.4.1)
|
5
5
|
activejob (>= 6.0)
|
6
6
|
activerecord (>= 6.0)
|
7
7
|
concurrent-ruby
|
@@ -9,66 +9,86 @@ PATH
|
|
9
9
|
GEM
|
10
10
|
remote: https://rubygems.org/
|
11
11
|
specs:
|
12
|
-
activejob (6.
|
13
|
-
activesupport (= 6.
|
12
|
+
activejob (6.1.1)
|
13
|
+
activesupport (= 6.1.1)
|
14
14
|
globalid (>= 0.3.6)
|
15
|
-
activemodel (6.
|
16
|
-
activesupport (= 6.
|
17
|
-
activerecord (6.
|
18
|
-
activemodel (= 6.
|
19
|
-
activesupport (= 6.
|
20
|
-
activesupport (6.
|
15
|
+
activemodel (6.1.1)
|
16
|
+
activesupport (= 6.1.1)
|
17
|
+
activerecord (6.1.1)
|
18
|
+
activemodel (= 6.1.1)
|
19
|
+
activesupport (= 6.1.1)
|
20
|
+
activesupport (6.1.1)
|
21
21
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
22
|
-
i18n (>=
|
23
|
-
minitest (
|
24
|
-
tzinfo (~>
|
25
|
-
zeitwerk (~> 2.
|
26
|
-
ast (2.4.
|
27
|
-
concurrent-ruby (1.1.
|
28
|
-
diff-lcs (1.
|
22
|
+
i18n (>= 1.6, < 2)
|
23
|
+
minitest (>= 5.1)
|
24
|
+
tzinfo (~> 2.0)
|
25
|
+
zeitwerk (~> 2.3)
|
26
|
+
ast (2.4.1)
|
27
|
+
concurrent-ruby (1.1.8)
|
28
|
+
diff-lcs (1.4.4)
|
29
29
|
globalid (0.4.2)
|
30
30
|
activesupport (>= 4.2.0)
|
31
|
-
i18n (1.8.
|
31
|
+
i18n (1.8.7)
|
32
32
|
concurrent-ruby (~> 1.0)
|
33
|
-
minitest (5.14.
|
33
|
+
minitest (5.14.3)
|
34
34
|
mysql2 (0.5.3)
|
35
|
-
parallel (1.
|
36
|
-
parser (
|
37
|
-
ast (~> 2.4.
|
35
|
+
parallel (1.20.1)
|
36
|
+
parser (3.0.0.0)
|
37
|
+
ast (~> 2.4.1)
|
38
38
|
pg (1.2.3)
|
39
|
+
rack (2.2.3)
|
39
40
|
rainbow (3.0.0)
|
40
|
-
rake (13.0.
|
41
|
+
rake (13.0.3)
|
42
|
+
regexp_parser (2.0.3)
|
41
43
|
rexml (3.2.4)
|
42
|
-
rspec (3.
|
43
|
-
rspec-core (~> 3.
|
44
|
-
rspec-expectations (~> 3.
|
45
|
-
rspec-mocks (~> 3.
|
46
|
-
rspec-core (3.
|
47
|
-
rspec-support (~> 3.
|
48
|
-
rspec-expectations (3.
|
44
|
+
rspec (3.10.0)
|
45
|
+
rspec-core (~> 3.10.0)
|
46
|
+
rspec-expectations (~> 3.10.0)
|
47
|
+
rspec-mocks (~> 3.10.0)
|
48
|
+
rspec-core (3.10.1)
|
49
|
+
rspec-support (~> 3.10.0)
|
50
|
+
rspec-expectations (3.10.1)
|
49
51
|
diff-lcs (>= 1.2.0, < 2.0)
|
50
|
-
rspec-support (~> 3.
|
51
|
-
rspec-mocks (3.
|
52
|
+
rspec-support (~> 3.10.0)
|
53
|
+
rspec-mocks (3.10.1)
|
52
54
|
diff-lcs (>= 1.2.0, < 2.0)
|
53
|
-
rspec-support (~> 3.
|
54
|
-
rspec-support (3.
|
55
|
-
rubocop (
|
55
|
+
rspec-support (~> 3.10.0)
|
56
|
+
rspec-support (3.10.1)
|
57
|
+
rubocop (1.8.1)
|
56
58
|
parallel (~> 1.10)
|
57
|
-
parser (>=
|
59
|
+
parser (>= 3.0.0.0)
|
58
60
|
rainbow (>= 2.2.2, < 4.0)
|
61
|
+
regexp_parser (>= 1.8, < 3.0)
|
59
62
|
rexml
|
60
|
-
rubocop-ast (>= 0.0
|
63
|
+
rubocop-ast (>= 1.2.0, < 2.0)
|
61
64
|
ruby-progressbar (~> 1.7)
|
62
|
-
unicode-display_width (>= 1.4.0, <
|
63
|
-
rubocop-ast (
|
64
|
-
parser (>= 2.7.
|
65
|
-
|
65
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
66
|
+
rubocop-ast (1.4.0)
|
67
|
+
parser (>= 2.7.1.5)
|
68
|
+
rubocop-bsm (0.5.4)
|
69
|
+
rubocop (~> 1.0)
|
70
|
+
rubocop-performance
|
71
|
+
rubocop-rails
|
72
|
+
rubocop-rake
|
73
|
+
rubocop-rspec
|
74
|
+
rubocop-performance (1.9.2)
|
75
|
+
rubocop (>= 0.90.0, < 2.0)
|
76
|
+
rubocop-ast (>= 0.4.0)
|
77
|
+
rubocop-rails (2.9.1)
|
78
|
+
activesupport (>= 4.2.0)
|
79
|
+
rack (>= 1.1)
|
80
|
+
rubocop (>= 0.90.0, < 2.0)
|
81
|
+
rubocop-rake (0.5.1)
|
82
|
+
rubocop
|
83
|
+
rubocop-rspec (2.1.0)
|
84
|
+
rubocop (~> 1.0)
|
85
|
+
rubocop-ast (>= 1.1.0)
|
86
|
+
ruby-progressbar (1.11.0)
|
66
87
|
sqlite3 (1.4.2)
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
zeitwerk (2.3.0)
|
88
|
+
tzinfo (2.0.4)
|
89
|
+
concurrent-ruby (~> 1.0)
|
90
|
+
unicode-display_width (2.0.0)
|
91
|
+
zeitwerk (2.4.2)
|
72
92
|
|
73
93
|
PLATFORMS
|
74
94
|
ruby
|
@@ -80,7 +100,7 @@ DEPENDENCIES
|
|
80
100
|
pg
|
81
101
|
rake
|
82
102
|
rspec
|
83
|
-
rubocop
|
103
|
+
rubocop-bsm
|
84
104
|
sqlite3
|
85
105
|
|
86
106
|
BUNDLED WITH
|
data/bin/fleiss
CHANGED
@@ -5,8 +5,8 @@ $LOAD_PATH.push(lib_dir) unless $LOAD_PATH.include?(lib_dir)
|
|
5
5
|
|
6
6
|
require 'fleiss/cli'
|
7
7
|
|
8
|
-
|
9
|
-
|
8
|
+
$stdout.sync = true
|
9
|
+
$stderr.sync = true
|
10
10
|
|
11
11
|
cli = Fleiss::CLI.instance
|
12
12
|
begin
|
@@ -14,7 +14,7 @@ begin
|
|
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
|
data/fleiss.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'fleiss'
|
3
|
-
s.version = '0.4.
|
3
|
+
s.version = '0.4.1'
|
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.)
|
@@ -23,6 +23,6 @@ Gem::Specification.new do |s|
|
|
23
23
|
s.add_development_dependency 'pg'
|
24
24
|
s.add_development_dependency 'rake'
|
25
25
|
s.add_development_dependency 'rspec'
|
26
|
-
s.add_development_dependency 'rubocop'
|
26
|
+
s.add_development_dependency 'rubocop-bsm'
|
27
27
|
s.add_development_dependency 'sqlite3'
|
28
28
|
end
|
@@ -8,7 +8,9 @@ module Fleiss
|
|
8
8
|
scope :in_queue, ->(qs) { where(queue_name: Array.wrap(qs)) }
|
9
9
|
scope :finished, -> { where.not(finished_at: nil) }
|
10
10
|
scope :not_finished, -> { where(finished_at: nil) }
|
11
|
-
scope :not_expired,
|
11
|
+
scope :not_expired, lambda {|now = Time.zone.now|
|
12
|
+
where(arel_table[:expires_at].eq(nil).or(arel_table[:expires_at].gt(now)))
|
13
|
+
}
|
12
14
|
scope :started, -> { where(arel_table[:started_at].not_eq(nil)) }
|
13
15
|
scope :not_started, -> { where(arel_table[:started_at].eq(nil)) }
|
14
16
|
scope :scheduled, ->(now = Time.zone.now) { where(arel_table[:scheduled_at].gt(now)) }
|
@@ -102,9 +104,12 @@ module Fleiss
|
|
102
104
|
private
|
103
105
|
|
104
106
|
def with_isolation(&block)
|
105
|
-
|
106
|
-
|
107
|
-
|
107
|
+
conn = self.class.connection
|
108
|
+
if conn.supports_transaction_isolation? && conn.adapter_name != 'SQLite'
|
109
|
+
self.class.transaction(isolation: :repeatable_read, &block)
|
110
|
+
else
|
111
|
+
yield
|
112
|
+
end
|
108
113
|
end
|
109
114
|
end
|
110
115
|
end
|
@@ -3,7 +3,7 @@ require 'fleiss/backend/active_record'
|
|
3
3
|
module Fleiss
|
4
4
|
module Backend
|
5
5
|
class ActiveRecord
|
6
|
-
class Migration < ::ActiveRecord::Migration[
|
6
|
+
class Migration < ::ActiveRecord::Migration[6.0]
|
7
7
|
def change
|
8
8
|
create_table :fleiss_jobs do |t|
|
9
9
|
t.string :queue_name, limit: 50, null: false
|
@@ -5,7 +5,7 @@ RSpec.describe Fleiss::Backend::ActiveRecord do
|
|
5
5
|
described_class.find(job.provider_job_id)
|
6
6
|
end
|
7
7
|
|
8
|
-
it '
|
8
|
+
it 'persists jobs' do
|
9
9
|
job = TestJob.perform_later
|
10
10
|
rec = retrieve(job)
|
11
11
|
|
@@ -28,25 +28,25 @@ RSpec.describe Fleiss::Backend::ActiveRecord do
|
|
28
28
|
)
|
29
29
|
end
|
30
30
|
|
31
|
-
it '
|
31
|
+
it 'enqueues with delay' do
|
32
32
|
job = TestJob.set(wait: 1.day).perform_later
|
33
33
|
rec = retrieve(job)
|
34
34
|
expect(rec.scheduled_at).to be_within(2.seconds).of(1.day.from_now)
|
35
35
|
end
|
36
36
|
|
37
|
-
it '
|
37
|
+
it 'enqueues with priority' do
|
38
38
|
job = TestJob.set(priority: 8).perform_later
|
39
39
|
rec = retrieve(job)
|
40
40
|
expect(rec.priority).to eq(8)
|
41
41
|
end
|
42
42
|
|
43
|
-
it '
|
43
|
+
it 'exposes active job ID' do
|
44
44
|
job = TestJob.perform_later
|
45
45
|
rec = retrieve(job)
|
46
46
|
expect(rec.job_id.size).to eq(36)
|
47
47
|
end
|
48
48
|
|
49
|
-
it '
|
49
|
+
it 'scopes pending' do
|
50
50
|
j1 = TestJob.perform_later
|
51
51
|
expect(retrieve(j1).start('owner')).to be_truthy
|
52
52
|
expect(retrieve(j1).finish('owner')).to be_truthy
|
@@ -58,7 +58,7 @@ RSpec.describe Fleiss::Backend::ActiveRecord do
|
|
58
58
|
expect(described_class.pending.ids).to eq [j4.provider_job_id, j2.provider_job_id]
|
59
59
|
end
|
60
60
|
|
61
|
-
it '
|
61
|
+
it 'scopes in_progress' do
|
62
62
|
_j1 = TestJob.perform_later
|
63
63
|
j2 = TestJob.perform_later
|
64
64
|
expect(retrieve(j2).start('owner')).to be_truthy
|
@@ -72,14 +72,14 @@ RSpec.describe Fleiss::Backend::ActiveRecord do
|
|
72
72
|
expect(described_class.in_progress('owner').ids).to eq [j2.provider_job_id]
|
73
73
|
end
|
74
74
|
|
75
|
-
it '
|
75
|
+
it 'scopes by queue' do
|
76
76
|
j1 = TestJob.perform_later
|
77
77
|
j2 = TestJob.set(queue: 'other').perform_later
|
78
78
|
expect(described_class.in_queue('test-queue').ids).to eq [j1.provider_job_id]
|
79
79
|
expect(described_class.in_queue('other').ids).to eq [j2.provider_job_id]
|
80
80
|
end
|
81
81
|
|
82
|
-
it '
|
82
|
+
it 'starts' do
|
83
83
|
job = TestJob.perform_later
|
84
84
|
rec = retrieve(job)
|
85
85
|
expect(rec.start('owner')).to be_truthy
|
@@ -88,7 +88,7 @@ RSpec.describe Fleiss::Backend::ActiveRecord do
|
|
88
88
|
expect(rec.started_at).to be_within(2.seconds).of(Time.zone.now)
|
89
89
|
end
|
90
90
|
|
91
|
-
it '
|
91
|
+
it 'locks atomically' do
|
92
92
|
24.times do
|
93
93
|
TestJob.perform_later
|
94
94
|
end
|
@@ -100,7 +100,7 @@ RSpec.describe Fleiss::Backend::ActiveRecord do
|
|
100
100
|
expect(counts.sum).to eq(24)
|
101
101
|
end
|
102
102
|
|
103
|
-
it '
|
103
|
+
it 'finishes' do
|
104
104
|
job = TestJob.perform_later
|
105
105
|
rec = retrieve(job)
|
106
106
|
expect(rec.finish('owner')).to be_falsey
|
@@ -112,7 +112,7 @@ RSpec.describe Fleiss::Backend::ActiveRecord do
|
|
112
112
|
expect(rec.finished_at).to be_within(2.seconds).of(Time.zone.now)
|
113
113
|
end
|
114
114
|
|
115
|
-
it '
|
115
|
+
it 'reschedules' do
|
116
116
|
job = TestJob.perform_later
|
117
117
|
rec = retrieve(job)
|
118
118
|
expect(rec.reschedule('owner')).to be_falsey
|
@@ -3,9 +3,10 @@ require 'fleiss/executor'
|
|
3
3
|
|
4
4
|
RSpec.describe Fleiss::Executor do
|
5
5
|
subject { described_class.new max_size: 2 }
|
6
|
+
|
6
7
|
after { subject.kill }
|
7
8
|
|
8
|
-
it '
|
9
|
+
it 'checks capacity' do
|
9
10
|
expect(described_class.new.capacity).to eq(1)
|
10
11
|
|
11
12
|
expect(subject.capacity).to eq(2)
|
@@ -15,7 +16,7 @@ RSpec.describe Fleiss::Executor do
|
|
15
16
|
expect(subject.capacity).to eq(0)
|
16
17
|
end
|
17
18
|
|
18
|
-
it '
|
19
|
+
it 'discards execution when capacity is reached' do
|
19
20
|
n = Concurrent::AtomicFixnum.new(0)
|
20
21
|
10.times do
|
21
22
|
10.times { subject.post { n.increment } }
|
data/spec/fleiss/worker_spec.rb
CHANGED
@@ -25,7 +25,7 @@ RSpec.describe Fleiss::Worker do
|
|
25
25
|
expect(yield).to be_truthy
|
26
26
|
end
|
27
27
|
|
28
|
-
it '
|
28
|
+
it 'runs' do
|
29
29
|
# seed 24 jobs
|
30
30
|
24.times {|n| TestJob.perform_later(n) }
|
31
31
|
wait_for { Fleiss.backend.not_finished.count.positive? }
|
@@ -39,7 +39,7 @@ RSpec.describe Fleiss::Worker do
|
|
39
39
|
expect(TestJob.performed).to match_array(0..23)
|
40
40
|
end
|
41
41
|
|
42
|
-
it '
|
42
|
+
it 'handles failing jobs' do
|
43
43
|
TestJob.perform_later('raise')
|
44
44
|
wait_for { Fleiss.backend.not_finished.count.zero? }
|
45
45
|
expect(Fleiss.backend.finished.count).to eq(1)
|
data/spec/fleiss_spec.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
RSpec.describe Fleiss do
|
4
|
-
it '
|
4
|
+
it 'has a backend' do
|
5
5
|
expect(described_class.backend).to eq(Fleiss::Backend::ActiveRecord)
|
6
6
|
end
|
7
7
|
|
8
|
-
it '
|
8
|
+
it 'enqueues' do
|
9
9
|
expect do
|
10
10
|
TestJob.set(wait: 1.week).perform_later
|
11
11
|
end.to change { described_class.backend.count }.by(1)
|
data/spec/spec_helper.rb
CHANGED
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.
|
4
|
+
version: 0.4.1
|
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:
|
11
|
+
date: 2021-01-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activejob
|
@@ -123,7 +123,7 @@ dependencies:
|
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '0'
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
|
-
name: rubocop
|
126
|
+
name: rubocop-bsm
|
127
127
|
requirement: !ruby/object:Gem::Requirement
|
128
128
|
requirements:
|
129
129
|
- - ">="
|
@@ -202,7 +202,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
202
202
|
- !ruby/object:Gem::Version
|
203
203
|
version: '0'
|
204
204
|
requirements: []
|
205
|
-
rubygems_version: 3.1.
|
205
|
+
rubygems_version: 3.1.4
|
206
206
|
signing_key:
|
207
207
|
specification_version: 4
|
208
208
|
summary: Minimialist background jobs backed by ActiveJob and ActiveRecord.
|